Skip to content

feat(protect): broaden Express body-parser recognition - #90

Merged
patchstackdave merged 3 commits into
mainfrom
feat/protect-express-broaden
Jul 16, 2026
Merged

feat(protect): broaden Express body-parser recognition#90
patchstackdave merged 3 commits into
mainfrom
feat/protect-express-broaden

Conversation

@patchstackdave

Copy link
Copy Markdown
Contributor

Builds on #89. The Express adapter only anchored on express.json(), so apps using express.urlencoded(), body-parser (bodyParser.json() / .urlencoded()), an aliased parser, or a destructured json() were scaffolded but left unwired (--check reported not-wired).

Broaden the anchor to any app.use(<x>.json(|urlencoded() — or a bare json(/urlencoded( — so the guard wires right after whichever parser populates req.body. No-parser apps are still intentionally left not-wired (the guard reads the express-parsed body; there's nothing to inspect without a parser).

+3 tests (urlencoded, body-parser, destructured json), 498 total. Comment/regex + tests only; no template or disclosure change.

patchstackdave and others added 2 commits July 16, 2026 08:52
The egress guard screened outbound calls by hostname, so a name that passes the check but resolves
to an internal/metadata IP (DNS rebinding, or just a hostname pointing inward) slipped through.

On the Node http/https path, inject a screening DNS `lookup` into the request options: resolve the
hostname, run each resolved address through the same egress predicate (so `internal_host` rules +
allowlist apply to the IP too), block if any is disallowed, and pin the connection to the vetted
resolution — closing the time-of-check/time-of-use gap. Only for real hostnames (literal IPs are
already covered by the sync check). Default on via `screenDns` (disable with `screenDns: false`);
needs node:dns/net, so it's a no-op on edge runtimes, where hostname rules still apply. Fail-open:
a resolver or injection error proceeds unscreened rather than breaking the request. `lookup` is
injectable for tests. The fetch/undici path is intentionally left for a follow-up.

+5 tests, 495 total, typecheck (incl. template check) + build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Express adapter only anchored on `express.json()`, so apps using `express.urlencoded()`,
body-parser (`bodyParser.json()`/`.urlencoded()`), an aliased parser, or a destructured `json()`
were scaffolded but left unwired. Broaden the anchor to any `app.use(<x>.json(|urlencoded()` (or a
bare `json(`/`urlencoded(`), so the guard wires after whichever parser populates req.body. No-parser
apps are still intentionally left not-wired (the guard reads the parsed body). +3 tests, 497 total.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderbuds

coderbuds Bot commented Jul 16, 2026

Copy link
Copy Markdown

Extended regex elegantly detects various body-parser invocations.

🎯 Quality: 100% Elite · 📦 Size: Small

📈 This month: Your 39th PR — above team average · Averaging Excellent

See how your team is trending →

Base automatically changed from feat/protect-egress-dns-rebinding to main July 16, 2026 07:43
@patchstackdave

Copy link
Copy Markdown
Contributor Author

/review

@patchstackdave
patchstackdave merged commit d1e75d5 into main Jul 16, 2026
4 checks passed
@patchstackdave
patchstackdave deleted the feat/protect-express-broaden branch July 16, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants