high · M3 · MASVS-NETWORK-1 · PTKD-VC-CORS-ANY-WITH-CREDENTIALS

    Backend allows any origin together with credentials (CORS)

    A backend or edge function answers with Access-Control-Allow-Origin set to * (or reflects any origin) and also allows credentials. Any website a signed-in user visits can then call your API with their session.

    How it is exploited

    An edge function reflects the Origin header and sets Access-Control-Allow-Credentials: true. A malicious page the signed-in user visits calls the API from their browser with their cookie and reads the answer.

    Why it matters

    Any website can read and change the user's data through your API while they are signed in (cross-site request with full read access).

    How to fix it

    1. Allow a fixed list of origins (your web app's domains); compare the Origin header against it.
    2. Never combine a wildcard or reflected origin with Allow-Credentials: true.
    3. Prefer bearer tokens in an Authorization header over cookies for API calls from the app.

    TypeScript (edge function)

    const ALLOWED = new Set(["https://app.example.com"]);
    const origin = req.headers.get("origin") ?? "";
    const headers = ALLOWED.has(origin)
      ? { "Access-Control-Allow-Origin": origin, "Access-Control-Allow-Credentials": "true", Vary: "Origin" }
      : {};

    Does your app have this?

    PTKD checks your build or your source project for PTKD-VC-CORS-ANY-WITH-CREDENTIALS and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M3)