Repository navigation
Secure API Lab Vulnerable vs Fixed
Last reviewed: 2026-11-28 (67 of 67 cases passed in CI run 46241150192; synthetic, illustrative teaching code only)
Prerequisites: Web application testing methodology ยท OWASP Top 10 overview ยท Web application security index ยท Linux with unshare and Python 3.12 for a local run.
Caution
Local teaching code only. impl/vulnerable_api.py is intentionally vulnerable: each group of routes carries a planted flaw, named in its comment by the case that detects it. Do not copy it, deploy it or expose it. It refuses to import unless the runner sets PNWC_SECURE_API_LAB=1, impl/ has no __init__.py (it is not a package), and both implementations are only served through labcore.serve, which refuses any address that is not loopback. The checks send requests only to 127.0.0.1. Run the techniques shown here only against systems you are authorized to test.
Important
Scope & safety: two implementations of the same small API, one with planted flaws and one with the control in place, are attacked by local checks over HTTP on 127.0.0.1 with an ephemeral port. By default the runner re-runs itself inside unshare -rn, a new network namespace in which only the loopback interface is brought up, and the first case checks that a connection to the RFC 5737 address 192.0.2.1 fails there. Users, passwords, bearer tokens, the RSA key, the webhook secret and every file are generated for the run in a temporary directory. Host names use example.test. The OAuth authorization server is an in-process object that never opens a socket. Nothing here is an assessment of a real application, framework or library.
Show each API control twice, with a check that tells the two apart, so the guidance in the methodology can point at observed behaviour:
- Object, function and property-level authorization (OWASP API Security Top 10 2023: API1, API5, API3).
- An OAuth 2.0 authorization-code client and OpenID Connect ID token validation (RFC 9700, RFC 7636, RFC 8725, OpenID Connect Core 1.0).
- Session and refresh-token lifecycle, request and response size limits, rate limiting, HTTP/1.1 request framing, file uploads, archives and XML parsing.
- Webhook signature verification, GraphQL limits, failing closed, and RFC 9457 error bodies.
For every case the expected outcome is the same: the check detects the flaw in the vulnerable implementation and does not detect it in the fixed one, and a legitimate request (the sanity check) works in both.
run_lab.py reads manifest.json. For each case it starts a fresh copy of each implementation on 127.0.0.1 and runs the case's check against it. Most checks are real HTTP requests; the six oidc-* checks call the implementation's ID token validator directly with forged tokens, oauth-code-reuse-revokes-tokens calls the in-process authorization server directly, and the six framing checks and the request-target part of client-input-errors-not-5xx write raw bytes to one socket because http.client refuses to send malformed framing. Each check returns flaw_detected and sanity_ok. A case passes only when the vulnerable side reports flaw_detected: true, the fixed side false, and both sanity checks hold.
The runner then writes an evidence manifest. It records the Python, Expat and platform versions, the isolation used, the addresses the servers bound, the installed dependency versions, the SHA-256 of every input, and the expected and observed result of each case. It exits non-zero on any failed or crashed case, an input hash mismatch, or a dependency version that differs from the pin. With --require-complete, a case that did not run also fails.
| Path | Content |
|---|---|
impl/labcore.py |
Shared plumbing: the loopback-only HTTP layer, the synthetic users and records, a fake clock, a stub policy service that can be switched off, the in-process OAuth/OIDC authorization server, and the GraphQL schema |
impl/vulnerable_api.py |
Intentionally vulnerable routes, each comment naming the case that detects its flaw |
impl/fixed_api.py |
The same routes with the control in place |
run_lab.py |
Stdlib runner and checks; it also builds the PNG, zip and XML fixtures in memory |
manifest.json |
Dependency pins, 48 cases with references, and the SHA-256 table of impl/*.py, run_lab.py and the requirements file |
requirements-secure-api.txt |
Hash-locked pins for pip --require-hashes --only-binary=:all:
|
evidence/ci-run-<id>.json |
Evidence downloaded from a CI run, named by run ID |
| Package | Version | Used for |
|---|---|---|
PyJWT (with the crypto extra) |
2.15.1 | The fixed ID token validator, and signing RS256 ID tokens at the mock authorization server |
| cryptography | 50.0.2 | RSA key generation and RS256; pulls in cffi 2.1.1 and pycparser 3.12 |
| defusedxml | 0.7.1 | The fixed XML parser (defusedxml.ElementTree.fromstring(..., forbid_dtd=True)) |
| graphql-core | 3.3.2 | Both GraphQL endpoints; the fixed one adds NoSchemaIntrospectionCustomRule and one custom validation rule (depth, aliases and expanded fields, counted through fragments) |
Versions and release dates were read from the PyPI JSON API on 2026-11-28; every pin is more than two weeks old. The vulnerable ID token verifier is hand-written on purpose. PyJWT 2.15.1 refuses to decode without an algorithms list, and it refuses an RSA public key as an HMAC secret, so the algorithm-confusion flaw cannot be shown with it.
.github/workflows/secure-api-lab.yml runs on pull requests and pushes that touch this folder, the test module or the workflow, and on workflow_dispatch. Its push trigger has no branch filter, like guide-tests.yml. It has permissions: contents: read, uses no secrets and requests no id-token. On ubuntu-24.04 with Python 3.12 it does the following:
- Run
tools/tests/test_secure_api_lab.pywithPNWC_SECURE_API_PRODUCING_EVIDENCE=1, which skips only the stale-evidence check. - Install the pinned dependencies with
pip --require-hashes --only-binary=:all:. - Allow unprivileged user namespaces (Ubuntu 24.04 restricts them through AppArmor) and check that
unshare -rn trueworks. - Run
run_lab.py --require-complete, then uploadsecure-api-evidence.jsonas the artifactsecure-api-evidence-<run id>.
guide-tests.yml runs the same test module without the skip, on every pull request and on pushes that touch WebAppSecurity/labs/** or tools/**, so committed evidence that no longer matches the inputs fails there.
python3 -m venv /tmp/secure-api-venv
/tmp/secure-api-venv/bin/pip install --require-hashes --only-binary=:all: \
-r WebAppSecurity/labs/secure-api/requirements-secure-api.txt
/tmp/secure-api-venv/bin/python -B WebAppSecurity/labs/secure-api/run_lab.py \
--require-complete --evidence /tmp/secure-api-evidence.json
python3 -B -m unittest tools/tests/test_secure_api_lab.py -vThe default --isolate unshare needs unprivileged user namespaces. --isolate none runs without the namespace; the servers still bind 127.0.0.1 only, but isolation-probe then fails, as it should. Without the namespace, the host's loopback is shared, so any other local process or user can reach the vulnerable server (including its XXE and zip-slip routes) on its ephemeral port while a case runs. Use it only on a single-user machine. --cases id1,id2 runs a subset. A local run writes evidence_origin: local-observed; only CI output (ci-observed) is committed.
The references are the requirement or section each check is built from: OWASP API Security Top 10 2023, OWASP ASVS 5.0.0 (tag v5.0.0_release), RFC 9700, RFC 7636, RFC 8725, OpenID Connect Core 1.0, RFC 6585, RFC 9110, RFC 9457, the Standard Webhooks specification and the OWASP Cheat Sheet Series. A case passing means the check behaved as expected on this code, not that the requirement is met in general.
| Case | Vulnerable implementation | Fixed implementation | References |
|---|---|---|---|
isolation-probe |
- | - | Egress to 192.0.2.1:443 gives ENETUNREACH, a closed loopback port gives ECONNREFUSED, and labcore.serve refuses 0.0.0.0, ::, 192.0.2.1 and host names |
bola-read-other-user-record |
Alice reads and rewrites Bob's invoice by ID | Ownership check; 404 and the record is unchanged | API1:2023 |
bfla-admin-route |
Any logged-in user lists users and disables Bob | Role check; 403 | API5:2023 |
bopla-mass-assignment |
role: admin in a profile update is stored |
Writable-property allowlist; 400 | API3:2023 |
bopla-excessive-data-exposure |
Profile returns email, password_hash, mfa_secret
|
Explicit public fields | API3:2023 |
oauth-redirect-uri-exact-match |
Prefix match sends a code to app.example.test.attacker.example.test
|
Exact string match | RFC 9700 ยง2.1, ยง4.1.3; ASVS 10.4.1 |
oauth-state-csrf |
No state: the victim is logged in as mallory |
state bound to a __Host- cookie; 400 |
RFC 9700 ยง2.1, ยง4.7.1 |
oauth-pkce-code-injection |
No PKCE: a stolen code logs the attacker in as Bob | S256 challenge; the AS refuses the attacker's verifier | RFC 9700 ยง2.1.1, ยง4.5; RFC 7636 ยง4.2, ยง4.6; ASVS 10.4.6 |
oauth-code-reuse-revokes-tokens |
AS policy: a reused code is refused, but the access token from the first redemption stays active | AS policy: the reuse is refused and that access token is revoked | RFC 6749 ยง4.1.2; RFC 9700 ยง4.2.4; ASVS 10.4.2 |
oidc-id-token-alg-none |
alg: none accepted |
algorithms=["RS256"] |
RFC 8725 ยง2.1, ยง3.1; ASVS 9.1.1, 9.1.2 |
oidc-id-token-alg-confusion |
HS256 MACed with the RSA public key PEM accepted | Same allowlist | RFC 8725 ยง3.1; ASVS 9.1.2 |
oidc-id-token-wrong-issuer |
Other iss accepted |
issuer= |
OIDC Core ยง3.1.3.7 step 2; RFC 8725 ยง3.8 |
oidc-id-token-wrong-audience |
Other aud accepted |
audience= and no extra audiences |
OIDC Core ยง3.1.3.7 step 3; RFC 8725 ยง3.9; ASVS 9.2.3, 10.5.4 |
oidc-id-token-expired |
Expired token accepted |
exp checked |
OIDC Core ยง3.1.3.7 step 9; ASVS 9.2.1 |
oidc-id-token-nonce-mismatch |
Another login's nonce accepted |
Nonce of this login transaction | OIDC Core ยง3.1.3.7 step 11; ASVS 10.5.1 |
session-rotation-on-login |
Planted pre-login session ID is authenticated after login | New ID on login, old one deleted | OWASP Session Management CS; ASVS 7.2.4 |
session-cookie-attributes |
sid=...; Path=/ |
__Host-sid=...; Path=/; Secure; HttpOnly; SameSite=Strict |
ASVS 3.3.1-3.3.4 |
session-logout-server-side |
Cookie saved before logout still works | Session deleted server-side | ASVS 7.4.1 |
session-idle-timeout |
Valid after 31 idle minutes | 15-minute idle, 8-hour absolute timeout | ASVS 7.3.1; OWASP Session Management CS |
refresh-token-rotation-reuse |
Same refresh token returned and reusable | Rotation; reuse revokes the family | RFC 9700 ยง4.14.2; ASVS 10.4.5 |
rate-limit-429-retry-after |
8 of 8 searches served | 429 with Retry-After after 5 |
API4:2023; RFC 6585 ยง4; RFC 9110 ยง10.2.3 |
max-page-size |
limit=100000 returns all 500 items |
Page capped at 50 | API4:2023 |
max-body-size |
1 MiB JSON body read and stored | 413 from Content-Length before reading |
API4:2023; RFC 9110 ยง15.5.14 |
content-length-negative |
Content-Length: -1: the body is read to EOF past the 16 KiB cap and stored |
400, connection closed | RFC 9112 ยง6.3; RFC 9110 ยง8.6; ASVS 4.2.1 |
content-length-non-numeric |
Content-Length: 4x is read as 0, so the body is answered as a second (smuggled) request |
400, connection closed | RFC 9112 ยง6.3; RFC 9110 ยง8.6; ASVS 4.2.1 |
transfer-encoding-rejected |
Transfer-Encoding: chunked ignored; the request inside the chunk is answered |
400, connection closed | RFC 9112 ยง6.1, ยง6.3; ASVS 4.2.1 |
conflicting-content-length |
Two Content-Length fields (0 and 52): the first wins and the body is answered as a request |
400, connection closed | RFC 9112 ยง6.3; ASVS 4.2.1 |
field-name-whitespace-before-colon |
Content-Length : 52 or Transfer-Encoding : chunked ends the header block in Python's email parser, so the body is answered as a second request |
Every raw field line checked against the token-then-colon grammar first; 400, connection closed | RFC 9112 ยง5.1; RFC 9110 ยง5.1; ASVS 4.2.1 |
field-value-bare-cr |
X-Pad: a<CR>Content-Length: 74 is split at the bare CR and 74 bytes are read as the body; a header section ended by a lone LF is accepted and the pipelined request after the body is answered |
CR, NUL and other CTLs except HTAB refused in field lines, and only CRLF ends the header section; 400, connection closed | RFC 9112 ยง2.2; RFC 9110 ยง5.5; ASVS 4.2.1 |
upload-type-by-content |
HTML named avatar.png stored under that name |
PNG signature + IHDR check, generated name | ASVS 5.2.2; OWASP File Upload CS |
archive-zip-slip |
../zip-slip-escaped.txt written outside the destination |
Every member resolved inside the destination first; a refused archive leaves no file behind | ASVS 5.3.3; Snyk Zip Slip |
archive-decompression-bomb |
16 MiB of zeros from a ~16 KiB zip extracted | Size, count and ratio checked before extracting; a refused archive leaves no file behind | ASVS 5.2.3; Python zipfile decompression pitfalls |
xml-external-entity |
SAX with external entities on returns a sandbox file |
defusedxml with forbid_dtd=True
|
OWASP XXE Prevention CS |
webhook-constant-time-compare |
Signature compared with ==
|
hmac.compare_digest |
Python hmac docs; Standard Webhooks |
webhook-stale-timestamp |
One-hour-old signed delivery processed | 5-minute tolerance | Standard Webhooks; Stripe webhook docs |
webhook-timestamp-non-ascii-digits |
Signed delivery with webhook-timestamp ending in ยฒ (U+00B2) processed |
ASCII digits only ([0-9]{1,12}); 401, not a 500 |
Standard Webhooks; Python str.isdigit docs |
webhook-replay |
Same delivery processed twice |
webhook-id remembered |
Standard Webhooks |
graphql-depth-limit |
Depth-8 query executes | Validation rule, depth 5 | ASVS 4.3.1; OWASP GraphQL CS |
graphql-alias-limit |
30 aliases execute | Validation rule, 10 aliases | ASVS 4.3.1; OWASP GraphQL CS |
graphql-introspection-disabled |
__schema answered |
NoSchemaIntrospectionCustomRule |
ASVS 4.3.2; OWASP GraphQL CS |
graphql-fragment-fanout |
~1 KB query of 25 fragments, each spreading the next twice (2^24 copies when expanded) and ending 9 fields deep, executes | Each fragment measured once (memoized); depth, aliases and expanded fields (limit 500) checked before graphql-core's own rules run; 400 | ASVS 4.3.1; OWASP GraphQL CS; API4:2023 |
graphql-aliases-through-fragments |
10 aliases as written execute as 52 through fragment spreads | Aliases counted as executed; 400 | ASVS 4.3.1; OWASP GraphQL CS |
fail-closed-authz-exception |
Policy outage means allow | Policy outage means 503 | ASVS 16.5.3; OWASP Top 10:2025 A10 (CWE-636) |
error-problem-details-no-stacktrace |
Python traceback as text/plain
|
application/problem+json, detail logged server-side |
RFC 9457 ยง3, ยง5; ASVS 16.5.1, 16.5.4 |
disabled-user-loses-access |
After an admin disables bob, his bearer token, an earlier session, password login and an earlier refresh token all still work |
disabled checked on every authentication path; his sessions and refresh-token families are ended at once |
ASVS 7.4.2; API2:2023 |
default-body-cap-json-routes |
1 MiB bodies to /login, /api/token/refresh, PATCH /api/users/me and PUT /api/invoices/101 are read and parsed |
16 KiB default cap for every route without its own limit, checked from Content-Length before authentication; 413 |
API4:2023; ASVS 5.2.1; RFC 9110 ยง15.5.14 |
login-throttling |
60 wrong passwords for alice, then the right one, all answered (the last with 200) | 429 with Retry-After after 5 failures per account and client (also 20 per client and 50 per account in 15 minutes), without checking the password; alice still logs in from 127.0.0.2
|
ASVS 6.1.1, 6.3.1; OWASP Authentication CS (account lockout); RFC 6585 ยง4 |
client-input-errors-not-5xx |
Empty zip member name, a file and a directory with one name, a 300-character member name and disabling user 99 give 500 with a traceback; the request-target http://[::1/x drops the connection |
400 or 404 with application/problem+json
|
ASVS 16.5.1, 16.5.4, 5.3.2; RFC 9457 ยง3 |
archive-contents-errors-not-5xx |
One-member zips with a corrupt deflate stream, the encrypted flag, compression method 9 (deflate64), the UTF-8 flag on a name that is not UTF-8, and a 1023-character but 4047-byte path, plus two-member zips with a valid central directory whose first local header sets the UTF-8 flag on the name \xff.txt, or whose end-of-central-directory record points 1000 bytes past the real central directory, give 500 with a traceback |
Encrypted members, methods other than stored and deflated, and names over 1024 bytes refused before extracting; zipfile, zlib, OS and value errors (including UnicodeDecodeError and a negative seek from zf.open()) mapped to 400; no file left behind |
ASVS 16.5.1, 5.2.3; PKWARE APPNOTE 4.4.4, 4.4.5; RFC 9457 ยง3 |
xml-encoding-errors-not-5xx |
XML declaring shift_jis, utf-32 or x-bogus gives 500 with a traceback |
Expat's ValueError and LookupError mapped to 400 |
ASVS 16.5.1; RFC 9457 ยง3 |
numeric-path-id-overflow-not-5xx |
A 5000-digit id on the four numeric routes makes int() raise (the 4300-digit limit) and gives 500 |
Ids are [0-9]{1,9}, so the router answers 404 |
ASVS 16.5.1; Python int_max_str_digits (CVE-2020-10735) |
login-throttling-concurrent-burst |
30 wrong passwords sent at once from one client all get a password check, then the right one gets 200 | The attempt is reserved under a lock before the password check: at most 5 checks, then 429; alice still logs in from 127.0.0.2
|
ASVS 6.3.1; OWASP Authentication CS; API2:2023; CWE-362 |
host-header-required-single |
HTTP/1.1 with no Host, two Host fields, Host: a b@c or Host: a:99999 is served |
400, connection closed | RFC 9112 ยง3.2; RFC 9110 ยง7.2; ASVS 4.2.1 |
duplicate-singleton-fields |
Two Authorization fields (alice, then bob) read bob's invoice because the last one wins; two Content-Type fields are accepted |
A second Host, Authorization, Content-Type, Cookie, Expect or webhook-* field is refused with 400 |
RFC 9110 ยง5.3; ASVS 4.2.1 |
server-errors-are-problem-json |
A bad request version, HTTP/2.0, an unknown method and 101 header fields get http.server's text/html pages that echo the method or version; an empty line before a request drops the connection |
application/problem+json with the standard reason phrase only; one leading empty line ignored; two leading empty lines, a leading bare LF or whitespace-only line, or two empty lines alone get 400 problem details instead of a dropped connection |
RFC 9457 ยง3; RFC 9112 ยง2.2; ASVS 16.5.1 |
header-section-size-cap |
A 40 KB header section (40 fields of 1000 bytes) is served | Field section capped at 16 KiB; 431 | RFC 6585 ยง5; API4:2023 |
slow-client-and-unread-body |
A connection that sends only a request line is still held after 8 s; a declared 1000-byte body that never arrives means no answer in 3 s; a head trickled one byte every 2 s is still held after 16 s | 5-second socket timeout per wait and a 10-second deadline for the whole head from its first byte (then 408 and close); the answer is sent before an unread body is discarded | API4:2023; RFC 9112 ยง9.5; RFC 9110 ยง15.5.9; CWE-400 |
expect-100-continue-respects-body-cap |
Expect: 100-continue with Content-Length: 1000000 on /login gets 100 (Continue) |
Route and its limit checked first: 413 without 100; a small body still gets 100, then 200 | RFC 9110 ยง10.1.1, ยง15.5.14; API4:2023 |
unauthenticated-state-bounded |
600 POST /session and 600 GET /oauth/login from an unauthenticated client are all kept |
Expired entries evicted; at most 8 anonymous sessions and 8 login transactions per client address (its own oldest goes) and 256 of each in all, then 429, so one client cannot evict another's; no empty login-failure windows | API4:2023; CWE-770 |
graphql-operation-selection |
Two operations and no operationName: 200 with an error; operationName ignored |
400 with the reason; operationName selects the operation |
GraphQL spec (October 2021) ยง6.1 GetOperation; ASVS 16.5.1 |
concurrent-connections-capped |
80 connections that each send one byte and stop get 80 server threads | At most 64 connections served at once; the rest get 503 problem details and are closed | API4:2023; RFC 9110 ยง15.6.4; CWE-770 |
webhook-replay-concurrent |
With 50,000 live ids in the replay cache, 20 concurrent copies of one delivery and every re-send are processed | Prune, check and record webhook-id under one lock, pruning in place: each delivery processed once, every re-send a duplicate |
Standard Webhooks; CWE-362 |
http-version-refused |
POST /api/notes HTTP/0.9 is stored and answered with no status line or headers; HTTP/1.2 is served |
HTTP/1.0 and HTTP/1.1 only; 505 problem details | RFC 9110 ยง15.6.6; RFC 9112 ยง2.3 |
body-stall-is-408 |
A note declaring 100 bytes that sends 5 and stalls gets no answer | 408 problem details and close, not 500 | RFC 9110 ยง15.5.9; RFC 9112 ยง8, ยง9.5 |
incomplete-body-refused |
A 7-byte note declared as 100 bytes, and a 24-byte PNG start declared as 5000, then end of stream: 201, and the truncated PNG is stored | 400 and close; the short body never reaches the route | RFC 9112 ยง8, ยง6.3 |
unauthenticated-storage-refused |
An avatar upload and a zip import with no Authorization are stored |
Bearer token required (401), and at most 32 MiB kept per user | API4:2023; OWASP File Upload CS; CWE-770 |
graphql-variables |
variables is ignored, so an operation with a required Int variable never runs, and a wrong-type or missing variable is 200 with an error |
variables must be an object; it is coerced first, a coercion error is 400, then the operation runs with it |
GraphQL spec (October 2021) ยง6.1.2 CoerceVariableValues |
Evidence: evidence/ci-run-46241150192.json, downloaded from the secure-api-evidence-46241150192 artifact of CI run 46241150192 (commit d013150).
-
Runner: Python 3.12.16 on
Linux-7.0.0-1020-azure-x86_64-with-glibc2.39,expat_2.9.0, isolationunshare -rn(verified: the only interface wasloand the namespace inode differed from the parent's); every server bound127.0.0.1. - Dependencies: PyJWT 2.15.1, cryptography 50.0.2, cffi 2.1.1, pycparser 3.12, defusedxml 0.7.1, graphql-core 3.3.2, all matching the pins.
-
Summary: 67 of 67 cases passed, with input hashes and dependency versions matching the manifest. In every non-probe case the vulnerable side reported
flaw_detected: true, the fixed sidefalse, and both sanity checks held.
| Case | Kind | Vulnerable (flaw detected) | Fixed (no flaw) | Observed |
|---|---|---|---|---|
isolation-probe |
isolation | egress ENETUNREACH, closed loopback port ECONNREFUSED
|
all four non-loopback binds refused | observed pass |
bola-read-other-user-record |
authz | read 200, write 200, record changed: true | read 404, write 404, record changed: false | observed pass |
bfla-admin-route |
authz | list 200, disable 200 | list 403, disable 403 | observed pass |
bopla-mass-assignment |
authz | 200, role after: admin
|
400, role after: user
|
observed pass |
bopla-excessive-data-exposure |
authz | sensitive fields: email, mfa_secret, password_hash
|
sensitive fields: none | observed pass |
oauth-redirect-uri-exact-match |
oauth | code sent to the attacker URI | invalid_request |
observed pass |
oauth-state-csrf |
oauth | callback 200, logged in as mallory
|
callback 400, not logged in | observed pass |
oauth-pkce-code-injection |
oauth | no PKCE, callback 200, logged in as bob
|
method S256, callback 400, not logged in, invalid_grant
|
observed pass |
oauth-code-reuse-revokes-tokens |
oauth | first redemption 200, reuse 400 invalid_grant, first access token still active |
first redemption 200, reuse 400 invalid_grant, first access token revoked |
observed pass |
oidc-id-token-alg-none |
oidc | accepted | InvalidAlgorithmError |
observed pass |
oidc-id-token-alg-confusion |
oidc | accepted | InvalidAlgorithmError |
observed pass |
oidc-id-token-wrong-issuer |
oidc | accepted | InvalidIssuerError |
observed pass |
oidc-id-token-wrong-audience |
oidc | accepted | InvalidAudienceError |
observed pass |
oidc-id-token-expired |
oidc | accepted | ExpiredSignatureError |
observed pass |
oidc-id-token-nonce-mismatch |
oidc | accepted | "nonce missing or does not match" | observed pass |
session-rotation-on-login |
session | planted ID after login: 200 | planted ID after login: 401 | observed pass |
session-cookie-attributes |
session |
sid, missing 4 of 4 |
__Host-sid, missing 0 of 4 |
observed pass |
session-logout-server-side |
session | replayed cookie: 200 | replayed cookie: 401 | observed pass |
session-idle-timeout |
session | after 31 min: 200 | after 31 min: 401 | observed pass |
refresh-token-rotation-reuse |
session | rotated: false, reuse 200, newest after reuse 200 | rotated: true, reuse 400, newest after reuse 400 | observed pass |
rate-limit-429-retry-after |
resource | 0 of 8 got 429 | 3 of 8 got 429, Retry-After: 60
|
observed pass |
max-page-size |
resource | 500 items | 50 items | observed pass |
max-body-size |
resource | 1 MiB body: 201 | 1 MiB body: 413 | observed pass |
content-length-negative |
framing | 201, 20492 bytes stored (cap 16 KiB) | 400, Connection: close
|
observed pass |
content-length-non-numeric |
framing | responses 400 then 200: smuggled request answered | one 400, Connection: close
|
observed pass |
transfer-encoding-rejected |
framing | responses 400 then 200: smuggled request answered | one 400, Connection: close
|
observed pass |
conflicting-content-length |
framing | responses 400 then 200: smuggled request answered | one 400, Connection: close
|
observed pass |
field-name-whitespace-before-colon |
framing |
Content-Length : 52 and Transfer-Encoding : chunked: responses 400 then 200 each, smuggled request answered |
one 400 each, Connection: close
|
observed pass |
field-value-bare-cr |
framing | bare CR: 201, 74 bytes read as the body; lone LF ending the header section: responses 201 then 200, pipelined request answered | one 400 each, Connection: close
|
observed pass |
upload-type-by-content |
parser | HTML as PNG: 201 | HTML as PNG: 415 | observed pass |
archive-zip-slip |
parser | 201, written outside: true | 400, written outside: false, files left: none | observed pass |
archive-decompression-bomb |
parser | 201, 16777216 bytes extracted | 413, 0 bytes extracted, files left: none | observed pass |
xml-external-entity |
parser | 200, secret in response: true | 400, secret in response: false | observed pass |
webhook-constant-time-compare |
webhook |
compare_digest calls: 0 |
compare_digest calls: 1 |
observed pass |
webhook-stale-timestamp |
webhook | 1-hour-old delivery: 200 | 1-hour-old delivery: 401 | observed pass |
webhook-timestamp-non-ascii-digits |
webhook | 200, processed | 401, not processed | observed pass |
webhook-replay |
webhook | processed 2 time(s) | processed 1 time(s) | observed pass |
graphql-depth-limit |
graphql | 200 | 400, "query depth 8 exceeds the limit of 5" | observed pass |
graphql-alias-limit |
graphql | 200 | 400, "30 aliases exceed the limit of 10" | observed pass |
graphql-introspection-disabled |
graphql | 200, schema returned | 400, introspection disabled error | observed pass |
graphql-fragment-fanout |
graphql | 1041-byte query: 200 in 0.143 s | 400 in 0.004 s, "query depth 9 exceeds the limit of 5" and "over a million fields after expanding fragments exceed the limit of 500" | observed pass |
graphql-aliases-through-fragments |
graphql | 200 (10 aliases written, 52 executed) | 400, "52 aliases exceed the limit of 10" | observed pass |
fail-closed-authz-exception |
errors | policy down: 200 | policy down: 503 | observed pass |
error-problem-details-no-stacktrace |
errors | 500 text/plain, traceback: true |
500 application/problem+json, traceback: false |
observed pass |
disabled-user-loses-access |
session | after disable: bearer 200, earlier session 200, password login 200, refresh 200 | after disable: bearer 401, earlier session 401, password login 401, refresh 400 | observed pass |
default-body-cap-json-routes |
resource | 1 MiB bodies: /login 401, PATCH /api/users/me 200, PUT /api/invoices/101 200, /api/token/refresh 400 |
413 on all four | observed pass |
login-throttling |
session | 60 of 60 wrong passwords 401, then the right one 200 | 5 x 401, then 55 x 429; right password 429 with Retry-After: 900; from 127.0.0.2 200; after 16 minutes 200 |
observed pass |
client-input-errors-not-5xx |
errors | three archives 500 text/plain, user 99 500, http://[::1/x connection dropped |
three archives 400, user 99 404, http://[::1/x 400, all application/problem+json
|
observed pass |
archive-contents-errors-not-5xx |
errors | all seven archives 500 text/plain; 1 file left |
all seven 400 application/problem+json (including the local-header UTF-8 flag and the misplaced end-of-central-directory offset); no file left |
observed pass |
xml-encoding-errors-not-5xx |
errors |
shift_jis, utf-32, x-bogus: 500 text/plain
|
400 application/problem+json each |
observed pass |
numeric-path-id-overflow-not-5xx |
errors | 5000-digit id: 500 text/plain on all four routes |
404 application/problem+json on all four |
observed pass |
login-throttling-concurrent-burst |
session | 30 concurrent wrong passwords: 30 password checks, 30 x 401; right password then 200 | 5 password checks: 5 x 401, 25 x 429; right password then 429; from 127.0.0.2 200 |
observed pass |
host-header-required-single |
framing | no Host, two Host, Host: a b@c, Host: a:99999: 200 each |
400 each, Connection: close
|
observed pass |
duplicate-singleton-fields |
framing | two Authorization: 200 (bob's invoice); two Content-Type: 201 |
400 each, Connection: close
|
observed pass |
server-errors-are-problem-json |
errors | bad version and HTTP/2.0: no response; FOO: 501 text/html echoing the method; 101 fields: 431 text/html; leading empty line and the four leading-garbage inputs: no response |
400, 505, 501, 431, all application/problem+json, no echo; leading empty line ignored: 200; two empty lines, bare LF, whitespace-only line, two empty lines alone: 400 application/problem+json each |
observed pass |
header-section-size-cap |
resource | 40141-byte request head: 200 | 431 application/problem+json; a 10-field head still 200 |
observed pass |
slow-client-and-unread-body |
resource | stalled connection still open after 8.0 s; unsent body: no response in 3 s; trickled head (8 bytes sent) still open after 16.0 s | stalled connection closed after 5.0 s; unsent body: 404 at once; trickled head answered 408 and closed after 10.0 s | observed pass |
expect-100-continue-respects-body-cap |
resource | 1000000-byte declared body: 100 | 413 without 100; small body: 100 then 200 | observed pass |
unauthenticated-state-bounded |
resource | 600 sessions kept (the twin keeps no login transactions or failure windows) | 8 sessions, 8 login transactions (the per-client caps), 41 login-failure keys | observed pass |
graphql-operation-selection |
graphql | two operations: 200 with "Must provide operation name..."; operationName: B did not run B |
400, "operationName is required when the document has more than one operation"; operationName: B ran B |
observed pass |
concurrent-connections-capped |
resource | 80 server threads for 80 one-byte connections | 64 threads; the other 16 answered 503 | observed pass |
webhook-replay-concurrent |
webhook | no replay cache: 20 concurrent copies plus one re-send processed 21 times; all 21 re-sends processed again | 50,000 ids prefilled: the copied delivery processed once; 0 processed twice; every re-send a duplicate | observed pass |
http-version-refused |
framing | HTTP/0.9 note stored, answered with no status line; HTTP/1.2: 200 | 505 application/problem+json each; nothing stored |
observed pass |
body-stall-is-408 |
errors | no answer in 8.0 s | 408 application/problem+json after 5.0 s, connection closed |
observed pass |
incomplete-body-refused |
framing | 7 of 100 bytes: 201; 24 of 5000 bytes: 201, truncated PNG stored | 400 each, Connection: close; nothing stored |
observed pass |
unauthenticated-storage-refused |
resource | upload 201, import 201, 2 files stored | upload 401, import 401, nothing stored; with alice's token 201 each | observed pass |
graphql-variables |
graphql |
{"i": 1} ignored (operation not run); wrong type and missing: 200 with an error |
{"i": 1} ran the operation; wrong type and missing: 400, "Variable '$i' has invalid value: Int cannot represent non-integer value: 'x'" |
observed pass |
- A pass shows that one check told one planted flaw apart from one fix, on this code. It does not show that the fixed implementation is free of other flaws, or that a framework or library is safe to use in another way.
-
oidc-*cases call the validator directly. OpenID Connect Core ยง3.1.3.7 allows a client to rely on TLS server validation instead of the signature for an ID token it receives directly from the token endpoint. The fixed client checks the signature anyway, as ASVS 9.1.1 asks for self-contained tokens, and the same validator also covers ID tokens that do not arrive that way. -
webhook-constant-time-compareis an instrumented check: it swaps the implementation'shmacmodule for a wrapper that countscompare_digestcalls. Measuring a timing difference over loopback would be noisy and is not attempted. -
xml-external-entitydepends on the parser configuration, not on the Expat version: the vulnerable side switches onfeature_external_geson purpose. The Expat version is recorded in the evidence. Entity expansion ("billion laughs") is not a case: Python's XML security documentation says Expat versions lower than 2.7.2 may be vulnerable to it. In local runs (not CI),xml.etree.ElementTree.fromstringrefused a 10^7-byte nested-entity document with "limit on input amplification factor (from DTD and entities) breached" on bothexpat_2.8.1(Python 3.12.13) andexpat_2.10.0(Python 3.14.10), so the vulnerable side would not show a flaw. The CI runner'sexpat_2.9.0was not tried. -
graphql-fragment-fanoutalso flags a reply slower than 5 seconds. The times in the table are one CI run's wall clock, not a benchmark. Locally (not CI), the fixed twin before this case existed, whose depth rule re-walked every fragment spread, did not answer the same query within the client's 30-second timeout. In the same local run against the previous fixed twin, seven of the eight cases added after the first review (the twofield-*framing cases,graphql-aliases-through-fragments,disabled-user-loses-access,default-body-cap-json-routes,login-throttlingandclient-input-errors-not-5xx) failed on the fixed side, andgraphql-fragment-fanouterrored with that timeout. - The upload check covers one content check (the PNG signature and IHDR chunk). It does not re-encode the image, strip metadata or scan for malware, which the OWASP File Upload Cheat Sheet also recommends.
- One process, in-memory state. Sessions, rate-limit windows, refresh-token families and the webhook replay cache are Python dictionaries, changed under one lock in the fixed twin (review round 3). A real deployment needs shared storage, and a rate limiter or replay cache per process is easy to bypass. The 256-entry caps on anonymous sessions and login transactions are global: many client addresses together can fill them, and new ones then get 429 until entries expire. Disk use is bounded per user (32 MiB), not overall.
-
No TLS. The servers speak plain HTTP on loopback. The
Securecookie attribute and the__Host-prefix are checked in theSet-Cookieheader, not by a browser. -
Mock authorization server. It is honest apart from two pluggable policies set by each twin: the redirect URI comparison and whether a reused authorization code also revokes the access tokens issued from it. Codes are single use in both. It enforces PKCE whenever a challenge was sent. Its
introspectis an in-process lookup in the shape of RFC 7662, not an HTTP endpoint, and the ID token issued at the first redemption is a signed JWT that revocation cannot recall. DPoP (RFC 9449), mTLS-bound tokens (RFC 8705), theissauthorization response parameter (RFC 9207) and RFC 7009 revocation are not exercised. -
Request framing.
labcoreframes requests itself on top ofhttp.server. After review round 2 the fixed twin also requires exactly one validHostin HTTP/1.1, refuses repeated single-value fields, caps the field section at 16 KiB, ends the header section only at CRLF, ignores one leading empty line, answershttp.server's own errors as problem details, times a stalled connection out after 5 seconds, and sends its answer before discarding an unread body. After review round 3 it also gives the whole request head 10 seconds from its first byte and a body 10 seconds (408 past either, so a client that trickles bytes cannot hold a thread for ever), refuses a body shorter thanContent-Length(400), serves HTTP/1.0 and 1.1 only (505), checks theHostport range, and serves at most 64 connections at once (503 beyond). One thread per connection remains: 64 slow clients can still hold every thread for up to 10 seconds each, and a 65th client then gets 503. The fixed twin uses strict framing:Content-Lengthonly as one field of ASCII digits up to 64 MiB, and anyTransfer-Encodingrefused with 400 (RFC 9112 ยง6.1 also allows 501 for a coding the server does not implement); the server then half-closes and discards what the client already sent. Before any of that, every raw field line must be a token, then:with no whitespace before it, then a value without CR, NUL or other CTLs except HTAB, ended by CRLF (RFC 9112 ยง2.2, ยง5.1, ยง5.2; RFC 9110 ยง5.5); Python'semailparser would otherwise drop such lines or split them at a bare CR. The vulnerable twin useslax_body_lengthand skips the field-line check, labelled as its planted flaw. There is no proxy in front, so the framing cases show a parser accepting what a front end could disagree with, not a full front-end/back-end desync. -
401 challenges. Every 401 from the fixed twin carries
WWW-Authenticate(RFC 9110 ยง15.5.2):Bearer realm="secure-api-lab"on token routes, witherror="invalid_token"only when a token was sent (RFC 6750 ยง3.1). The cookie-session and webhook routes have no registered scheme, so they use the lab's ownSessionandWebhook-Signaturenames. Login answers for unknown and known usernames both cost one PBKDF2 run (ASVS 6.3.8); that is checked by a unit test, not timed. -
Login throttling. Failed logins are counted per account and client address, per client and per account in a 15-minute sliding window (limits 5, 20 and 50). A throttled attempt gets 429 with
Retry-After, is not checked against the password and is not counted, and the throttle ends with the window. Because the account-and-client limit trips first, one client cannot lock another client out of an account (the check shows alice logging in from127.0.0.2). Failures spread over many addresses can still reach the per-account limit and delay the real user for up to 15 minutes; the OWASP Authentication Cheat Sheet warns that lockout can be used for denial of service and suggests, for example, still allowing the forgotten-password flow. The lab has no such flow, CAPTCHA or MFA step-up. - Fixed limits are lab values. The 50-item page, 16 KiB default request body and note, 1 MiB upload, 4 MiB uncompressed archive, 5 requests per 60 seconds, login throttle of 5, 20 and 50 failures in 15 minutes, 15-minute idle timeout and GraphQL depth 5, 10 aliases and 500 expanded fields were chosen for the lab, not taken from a standard.
- gRPC is not covered. The lab has no gRPC service.
-
Known open findings (final adversarial review, round 3). Three fix-and-attack rounds closed every authorization, input-validation and framing bypass the reviewers confirmed. These availability and resource limits were found in the last round and are deliberately left open; they are documented here rather than claimed fixed:
- Connection slots after a refusal. After answering a 4xx, a connection's thread keeps draining the unread body under a per-read timeout and a 4 MiB budget but no overall deadline, so a slow sender can keep one of the 64 slots busy well past the 10-second head/body deadlines. Enough such clients hold every slot and new clients get 503. Suggested fix: give the drain loop an overall deadline (for example 2 seconds).
- No per-client share of the 64 connections. One client address can take all of them.
- Global caps on anonymous state. The 256 OAuth login transactions and anonymous sessions are global and live for up to 600 seconds, so one client can keep OAuth login unavailable for everyone by refreshing transactions. Shorter lifetimes, per-prefix caps or stateless (encrypted) transactions would bound this.
- Refresh-token store growth. Used refresh tokens and revoked families are never pruned and there is no per-user family cap, so an authenticated user can grow server memory without limit.
-
Expect: 100-continueedge cases. The server sends100 Continuebefore refusing an unsupported HTTP version with 505, and it invites a body on authenticated upload and import routes before checking the bearer token (the body is then answered with 401 and drained).
- Web application testing methodology: Phase 4 (authentication and session) and Phase 8 (API and GraphQL)
- OWASP ASVS & Nuclei assessment: how to cite ASVS requirement IDs in a report
- OAuth consent investigation and token theft & session revocation: the identity-provider side
- Software supply-chain lab: the CI evidence layout this lab follows
โฌ ๏ธ Web Application Security index | Master Index | ๐ฏ Role Navigation | Legal Notice
๐ Source: WebAppSecurity/labs/secure-api/README.md | โ๏ธ Suggest an edit | โฌ
๏ธ Back to Web App Security
- ๐บ๏ธ Browse by Topic
- ๐ All Repository Files
- ๐งญ Learning Paths
- ๐ Master Guide
- ๐ค Glossary
- โ๏ธ Legal & Disclaimer
๐ Foundations & Learning
๐ก๏ธ Defense & Investigations
- Incident Response
- Open Source Intelligence (OSINT)
- Reverse Engineering
- Operations Security (OPSEC)
- Compliance
โ๏ธ Platforms & Infrastructure
๐ก Hardware, Wireless & Field Projects
- PNWC Cyberdeck
- Hardware Testing
- Hardware Hacking
- Software-Defined Radio
- Wardriving
- uConsole
- Space Security
๐งฐ Assessment & Field Reference
๐ฆ Downloads & Project Resources
๐๏ธ Additional Topics