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
- Allow a fixed list of origins (your web app's domains); compare the Origin header against it.
- Never combine a wildcard or reflected origin with Allow-Credentials: true.
- 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 appReferences
Related checks (M3)
- Permissive CORS with credentials
- State-changing request succeeded without authentication
- Weak JWT observed on the wire
- Biometric authentication not bound to a cryptographic key
- Premium access is stored on the phone and trusted (heuristic)
- Firebase rules trust an email address nobody verified
- Firebase security rules open to everyone
- Users can make themselves admin or premium in Firestore