Skip to content

feat(rules): flag predictable sequential resource ids in API endpoints (advisory) #2322 - #2365

Open
longshore-nc9[bot] wants to merge 4 commits into
mainfrom
feat/2322-sequential-resource-ids
Open

longshore-nc9[bot] wants to merge 4 commits into
mainfrom
feat/2322-sequential-resource-ids

Conversation

@longshore-nc9

@longshore-nc9 longshore-nc9 Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Adds security/sequential-resource-ids, a passive advisory rule. It reads the endpoint discovery results and flags same-origin API endpoints keyed by a small integer (/api/orders/42, or ?user_id=7 on an API path), grouped per path pattern. It sends no request at any probe level. UUIDs, ULIDs, hashes, slugs, long numbers, counters (page, v1, limit, year) and plain navigation links are not flagged. Findings are warnings worded as IDOR-prone advisories that say an unauthenticated crawl cannot prove cross-account access.

Scope (decision from the dispatcher, AC narrowed on #2322): detection covers ids in URL paths and query strings of discovered endpoints. Ids inside JSON response bodies are out of scope: site rules do not receive fetched bodies, and reading them would need a new request or collector, so the rule stays passive. JSON id fields in inline page data are tracked in #2369. The docs page says so.

The live rule count crosses 360, so PUBLIC_RULE_COUNT_FLOOR and every "350+" copy are bumped to 360+. The private repo's website copy needs the same floor.

Commands run:

  • bun run scripts/test-suites.ts --run rules (12993 pass, 0 fail)
  • bun run scripts/test-suites.ts --run rest (3968 pass, 0 fail)
  • bun test ./packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts (1 pass); golden-finding-messages-229 (3 pass, no snapshot diff)
  • bun run typecheck in packages/rules, make validate in docs, bun scripts/changelog.ts check, oxlint on the new files

Docs: docs/rules/security/sequential-resource-ids.mdx, hub, docs.json, counts. Skill: none.

Closes #2322

@longshore-nc9
longshore-nc9 Bot marked this pull request as ready for review November 25, 2026 08:31
@longshore-nc9
longshore-nc9 Bot requested a review from nc9 as a code owner November 25, 2026 08:31
@longshore-nc9

longshore-nc9 Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Automated review

Reviewed head 38db07a (up to date with main) against #2322, including the narrowed AC1 recorded on the issue (JSON id fields moved to #2369).

Findings

1. [verified, blocking] Every WordPress post or page gets an "IDOR-prone" warning for its public REST link
WordPress puts <link rel="alternate" type="application/json" href=".../wp-json/wp/v2/posts/<id>"> in the head of every post and page. extractEndpointRefsFromDocument keeps it as link-href, because wp-json matches API_PATH_RE. In the new rule, LINK_VIA would skip a link-href candidate, but the v2 segment makes looksLikeApiPath true, so the skip never applies. posts/123 then matches the collection-word path check.

So a large share of the web (any WordPress site whose crawl reaches a post or page) gets an IDOR advisory about public content. WordPress REST already enforces post visibility. The PR body does not report the AGENTS.md step 9 smoke test on about 25 real websites, which would have caught this.

Suggested fix: exclude link-href (and script-src) candidates even on API paths, or at least the WordPress wp-json/wp/v2/<type>/<id> alternate links. Add a regression test that builds the surface from real head markup, not from a hand-made candidate.

2. [verified, minor] /api/42 is reported as /api/{id}
api counts as a collection word. That is arguable, but the pattern reads oddly.

3. [verified, minor] Cursor and pagination keys maxId and sinceId match ID_KEY
/api/orders?sinceId=10 is flagged. These keys page through results; they do not name a record.

4. [verified, minor] /api/orders/42.json is not flagged
The docs list a .json ending as an API signal, but the id segment 42.json fails SMALL_INT.

5. [verified, minor] The PR will not close #2322
The PR has no closingIssuesReferences. Add "Closes #2322" to the body if that is intended.

Things I checked that hold up:

  • Clamping: MAX_URL_CHARS caps URLs at 512, and segment, segment-count and query-param caps bound the loops.
  • Composite keys use JSON.stringify.
  • Query keys that reach the output are limited to ID_KEY characters.
  • Rule-time I/O: the rule makes no fetch, and the existing test checks this at every probe level.
  • Default runs: the engine builds endpointSurface in adapter.ts with no probe-level gate, so the rule runs in a default audit.

Acceptance criteria (#2322)

  • Small-integer ids in path segments and query parameters of discovered endpoint URLs (JSON ids moved to sequential-resource-ids: also check id fields in inline page JSON #2369 by the recorded decision). Met: findSequentialId and its tests. Finding 1 is an over-match, not a miss.
  • Advisory wording that says an unauthenticated crawl cannot prove cross-account access. Met: LIMIT_NOTE, asserted in the test.
  • UUIDs and opaque ids not flagged. Met: UUID, ULID, hash, long-number and slug cases in the tests.
  • No requests sent; passive; runs with no --probe. Met: the stubFetch test at all levels, and the engine builds the surface ungated.
  • Fixture tests and a docs page under docs/rules/security/. Met.

Checks run locally (CI has not run)

  • bun run scripts/test-suites.ts --run rules: 13,002 pass, 0 fail.
  • New rule test plus the registry-wide rule tests (verdict scope, finding scope, meta limits, max rules, docs rule pages, docs category table, rule-count-docs-2139): 1,222 pass, 0 fail.
  • streaming-rules-canonical-golden: pass. golden-finding-messages-229: pass.
  • bun run typecheck in packages/rules: exit 0.
  • oxfmt --check and oxlint on the new files: exit 0.
  • bun run docs:check: exit 0.
  • scripts/test-suites.ts --check: OK.
  • bun run changelog: includes the entry.
  • Not run: the rest and cli suites.

Evidence: skipped. This is not a visual run.

VERDICT: changes-requested

@longshore-nc9

longshore-nc9 Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Automated review

Delta review of head 2453fda (up to date with main) against the previous automated review of 38db07a (changes-requested) and #2322, including the narrowed AC1 recorded on the issue (JSON id fields moved to #2369). The fix round is one commit, 2453fda, touching the rule, its test and its docs page.

Previous findings

  1. WordPress wp-json/wp/v2/posts/<id> head link flagged as IDOR-prone (was blocking): fixed, verified. The new ALWAYS_SKIP_VIA check drops every link-href and script-src candidate before the API-path check. I ran real WordPress head markup (<link rel="alternate" type="application/json" href=".../wp-json/wp/v2/posts/18066">, a relative /wp-json/wp/v2/pages/42, and a <script src="/api/v1/widgets/7">) through parsePage → extractEndpointRefsFromDocument → buildEndpointSurface → rule.run. All three are extracted as link-href/script-src candidates, and the rule now returns pass. With the rule file from 38db07a, the same input returned warn ("IDOR-prone"). I also checked a page that has the head link and an inline fetch("/wp-json/wp/v2/posts/5"). The surface keeps the fetch record, because a record with a method wins over the method-less link, and the rule still warns on it. That is right: a URL used in a script is a real call.
  2. /api/42 reported as /api/{id}: fixed, verified. A number right after an API_WORDS segment is skipped.
  3. maxId / sinceId cursor keys: fixed, verified. CURSOR_KEYS is compared lowercased, so it covers sinceId, sinceID and since_id.
  4. /api/orders/42.json not flagged: fixed, verified. The pattern is now /api/orders/{id}.json.
  5. PR did not close feat(rules): flag predictable sequential resource IDs in API endpoints (advisory) #2322: fixed. The body has "Closes feat(rules): flag predictable sequential resource IDs in API endpoints (advisory) #2322", and closingIssuesReferences lists feat(rules): flag predictable sequential resource IDs in API endpoints (advisory) #2322.

The tests bite: I reverted the three code changes, and the 5 new negative tests failed (/api/42, maxId, sinceId, since_id, the WordPress link). They passed again after I restored the code.

New findings (none blocking)

  1. [verified, minor] The new if in findSequentialId is not formatted. oxfmt --check packages/rules/src/security/sequential-resource-ids.ts exits 1 on the hand-wrapped condition at about line 176. The file was clean at 38db07a. CI does not format packages/rules, but this is a new file, so running oxfmt on it causes no churn.
  2. [verified, minor] Some cursor key spellings are not covered. findSequentialId still flags /api/orders?since-id=10 and /api/orders?next_id=10, because CURSOR_KEYS has no hyphenated forms and no next/prev/from/until keys. These spellings are uncommon, and the finding is only an advisory warning.
  3. [verified, minor] services collections are now missed. services is in API_WORDS, so the new API_WORDS.has(prev) skip drops /api/services/42 and /v1/services/7. Both return null. This is a small false negative. Narrowing the skip to api and rest would fix it.
  4. [verified, minor] The WordPress regression test uses a hand-made candidate, not head markup. The previous review asked for a test that builds the surface from real head markup. The test still passes a hand-made link-href candidate. My end-to-end run above shows the pipeline behaves correctly, but nothing in the suite covers it.
  5. [verified, minor] The PR body reports no AGENTS.md step 9 smoke test. I ran a small one myself: about 25 well-known pages, fetched and run through parsePage → extractEndpointRefsFromDocument → buildEndpointSurface → rule.run, one page each. There were no non-pass results. Most pages produced no candidates, and 2 fetches returned bot stubs. The wordpress.org post cited last round produced no refs at all, because API_PATH_RE in endpoint-surface.ts only matches /wp-json at the root of the path, and that install sits under /news/. That behaviour existed before this PR.

Acceptance criteria (#2322)

  • Rule detects small-integer or sequential id patterns in discovered endpoint URLs (path segments and query parameters); JSON id fields in inline page data moved to sequential-resource-ids: also check id fields in inline page JSON #2369 Met. findSequentialId handles path ids (now including .json endings) and query ids. The tests cover both, and the WordPress over-match is gone.
  • Findings are worded as advisory (IDOR-prone), not a confirmed vulnerability, and state that an unauthenticated crawl cannot prove cross-account access. Met. The LIMIT_NOTE wording is unchanged and still asserted in the test.
  • UUIDs and other opaque ids are not flagged. Met. The UUID, ULID, hash, long-number and slug tests are unchanged and pass.
  • No cross-account or id-enumeration requests are sent (passive, runs with no --probe flag). Met. The rule fetches nothing, and the stubFetch test covers every probe level. The endpoint surface is built with no probe gate.
  • Fixture tests and a docs page under docs/rules/security/. Met. The new tests are in packages/rules/tests/sequential-resource-ids.test.ts, and docs/rules/security/sequential-resource-ids.mdx now lists the new exclusions.

Checks run locally (CI has not run)

  • bun run scripts/test-suites.ts --run rules: 13,008 pass, 0 fail.
  • streaming-rules-canonical-golden and golden-finding-messages-229: 4 pass, 0 fail.
  • End-to-end WordPress head repro (parsePage → surface → rule): pass at 2453fda, warn with the rule file from 38db07a.
  • Real-page smoke test, about 25 sites: no non-pass results (finding 5).
  • Revert check for the new tests: 5 fail with the fixes reverted, all pass with them restored.
  • bun run typecheck in packages/rules: exit 0.
  • oxlint on the changed files: exit 0. oxfmt --check: exit 1 (finding 1).
  • bun run docs:check: exit 0.
  • scripts/test-suites.ts --check: OK. changelog.ts check: OK.
  • Not run: the rest and cli suites. This round touches nothing outside packages/rules and docs/.

Evidence: skipped. This is not a visual run: #2322 has no ls:visual label, and the change has no UI or CLI-layout effect.

VERDICT: approve

@longshore-nc9
longshore-nc9 Bot force-pushed the feat/2322-sequential-resource-ids branch 2 times, most recently from 62770e3 to 7dd0557 Compare November 26, 2026 12:00
nc9 added 4 commits November 26, 2026 12:33
…rce-ids #2322

Format the query-key condition as oxfmt writes it. Fold case, - and _
when matching cursor keys and add next, prev and until. Flag a number
after services again, since /api/services/42 is a record. Cover the
WordPress head markup end to end through the endpoint surface.

Signed-off-by: nc9 <[email protected]>
@longshore-nc9
longshore-nc9 Bot force-pushed the feat/2322-sequential-resource-ids branch from 7dd0557 to 58c8982 Compare November 26, 2026 12:41

This branch has not been deployed

No deployments
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.

feat(rules): flag predictable sequential resource IDs in API endpoints (advisory)

1 participant