CCyberwiki

Attack surface

Every page, form field, API route, cookie, header, file upload and open network port that answers requests from outside belongs to a web application's attack surface: the set of points on a system's boundary where an attacker can try to get in, cause an effect or take data out.1

Components

An application's attack surface has four parts: the paths by which data and commands enter and leave it; the code that guards those paths, such as Authentication, Authorization, logging, validation and encoding; the valuable data it holds, including secrets, keys and personal data; and the code that protects that data, such as encryption and access auditing.2

Entry and exit points include interface forms and fields, HTTP headers and cookies, APIs, files, databases, other local storage, email and other messages, and runtime arguments. A real application can have thousands of them, so they are grouped by function: login, admin interfaces, search, data entry forms, business workflows, transaction APIs, monitoring interfaces and connections to other systems.2

Mapping

The map comes from reading the design and the source code for points of entry and exit, then walking through the main use cases (sign up, log in, search, place an order) and following where each piece of data is checked and stored. A DAST tool such as ZAP can crawl the running application and list what is reachable over the web.2

Each point then goes into a group by exposure (internet-facing or internal), purpose and technology. The count per group shows how much review the application needs and makes a change in its risk visible without anyone reading every endpoint. User roles are laid over the map, with most attention at the two ends of the range: anonymous visitors, who need no account to reach a point, and administrators, whose functions carry the highest privileges.2

Security testers build this map before any other test. Each request is recorded through an intercepting proxy, with its parameters, its HTTP method, whether it requires a login and whether it is part of a multi-step process. Hidden form fields get special attention, because they often carry values such as a price or a quantity that the developer never meant a visitor to change.3

Attackers map the same surface from outside, by scanning IP ranges, scanning for known vulnerabilities and requesting paths from a wordlist. What a scan finds can lead to initial access, for example by exploiting a public-facing application.4

Measurement

Michael Howard at Microsoft and other researchers proposed the Relative Attack Surface Quotient (RSQ), a single score recalculated as a system and its deployment change. Researchers at Carnegie Mellon later defined a formal attack surface metric, for large systems such as SAP. It adds up entry and exit points, channels (TCP and UDP ports, RPC endpoints, named pipes) and untrusted data items, and weights each by the ratio of the damage it could allow to the effort an attacker needs to use it.2

Growth

The surface usually grows as interfaces, user types and integrations are added. The first web page opens it considerably; a further field or page built the same way adds little new risk. A new web service API or a file upload from the internet carries a different kind of risk and needs its own assessment.2

Part of the surface is left over from earlier work. Old versions still deployed, features kept in case they are needed again, unused code and backup copies all count, and backups of code and data are often forgotten.2

Changes to login, sessions, passwords, roles, admin functions, encryption, secrets handling or the server and database platform alter the surface directly. The map and the threat model feed each other: a change to the surface should trigger a new threat model, and threat modelling improves the map.2

Reduction

The surface gets smaller when the model is simpler (fewer user levels, no confidential data stored without need), when unused features and interfaces are turned off, and when operational controls such as a web application firewall sit in front of the application.2

Next.js

A direct POST request can call an exported Server Action without going through the page that uses it. Each Server Action therefore has to check the session and the ownership of the record itself.5

'use server'
export async function deletePost(postId) {
  const session = await auth();
  if (!session?.user) throw new Error('Unauthorized');
  const post = await db.post.findUnique({ where: { id: postId } });
  if (post.authorId !== session.user.id) throw new Error('Forbidden');
  await db.post.delete({ where: { id: postId } });
}

Supabase

On existing Supabase projects, new tables and functions in the public schema receive grants for the anon and authenticated roles, which makes them reachable through the Data API even when nobody meant to publish them. Turning off Automatically expose new tables in the Data API settings stops this for new tables. A separate schema such as api holds only what the API should serve and keeps internal tables out of it. A project that never uses the client libraries or the REST and GraphQL endpoints can switch the Data API off entirely. Grants decide which tables a role can reach; row level security decides which rows.6

In SecFlash

On the Security page, SecFlash lists live subdomains as SF-SEC-304, public test and staging hosts as SF-SEC-305, risky open ports as SF-SEC-302 and admin panels open to the internet as SF-SEC-310. The Exposure page reports a public OpenAPI or Swagger file as SF-EXP-204 and private-looking routes named in the site's JavaScript as SF-EXP-201. On the server it is installed on, it reports an unexpected port that accepts connections from outside as SF-SRV-103 on the Server page and a program that starts listening on a new port as SF-DET-301 on the Detections page.

See also

References

  1. back NIST. "attack surface". CSRC Glossary, citing NIST SP 800-53 Rev. 5.
  2. a b c d e f g h i OWASP Cheat Sheet Series. "Attack Surface Analysis Cheat Sheet". OWASP.
  3. back OWASP (2020). "WSTG-INFO-06: Identify Application Entry Points". OWASP Web Security Testing Guide v4.2.
  4. back MITRE. "Active Scanning, Technique T1595". MITRE ATT&CK.
  5. back Vercel. "Data Security". Next.js documentation.
  6. back Supabase. "Hardening the Data API". Supabase documentation.