Skip to content

INTER-2613: fix: reject prototype keys in region validation - #294

Merged
JuroUhlar merged 1 commit into
mainfrom
fix/region-prototype-keys
Oct 27, 2026
Merged

JuroUhlar merged 1 commit into
mainfrom
fix/region-prototype-keys

Conversation

@JuroUhlar

@JuroUhlar JuroUhlar commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

getValidRegion used region in Region. in also matches prototype keys, so ?region=toString (or constructor, hasOwnProperty) passed validation. getIngressAPIHost then built the host from the raw value: https://toString.api.fpjs.io.

Found during the INTER-2613 spike.

Changes

  • proxy/utils/region.ts: validate with an isRegion type guard (Object.values(Region).includes(...)). This also removes the type assertion and its eslint-disable comment.
  • proxy/handlers/ingress.ts: build the host prefix from the validated region.
  • Tests:
    • New proxy/utils/region.test.ts.
    • The invalid-region cases in ingress.test.ts and ingress_v4.test.ts now cover prototype keys.
    • These ingress tests could never fail before: the URL assertion ran inside the mocked request, where transport.ts caught the error. The assertion now runs after the handler returns, with the corrected expected URL.
  • Changeset: patch.

Checks

pnpm lint, pnpm test:dts and pnpm test pass (22 files, 165 tests). Before the fix, 10 prototype-key tests failed.

Follow-up

The "Suffix with a dot" ingress tests use the same never-failing assertion pattern. They are not changed here.


Generated by Claude Code

`region in Region` also matched inherited keys such as `toString` or
`constructor`, so `?region=toString` routed requests to
`https://toString.api.fpjs.io`. Validate against the enum values instead,
and build the ingress host prefix from the validated region.

The invalid-region ingress tests asserted inside the mocked
`https.request`, where the transport layer swallowed failures. They now
assert after the handler returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RrYGTcXedRKZWrV3LUKzDw
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Following releases will be created using changesets from this PR:

@fingerprint/azure-frontdoor-proxy@2.2.2

Patch Changes

  • Treat region query values that match object prototype keys, such as toString, as invalid and route them to the default us region (dfe9ae7)

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

St.❔
Category Percentage Covered / Total
🟢 Statements
95.58% (+0.01% 🔼)
324/339
🟢 Branches 88.51% 131/148
🟢 Functions
96.81% (+0.03% 🔼)
91/94
🟢 Lines
95.5% (+0.01% 🔼)
318/333

Test suite run success

165 tests passing in 57 suites.

Report generated by 🧪jest coverage report action from dfe9ae7

Show full coverage report
St File % Stmts % Branch % Funcs % Lines Uncovered Line #s
🟢 All files 95.57 88.51 96.8 95.49
🟢  management 94.84 82.85 100 94.84
🟢   github.ts 97.05 86.36 100 97.05 96
🟢   healthCheck.ts 100 80 100 100 46
🟢   rollback.ts 100 100 100 100
🟡   semver.ts 66.66 100 100 66.66 7
🟢   settings.ts 100 100 100 100
🟢   site.ts 100 83.33 100 100 55
🟢   storage.ts 83.33 50 100 83.33 10-11,33
🟢  proxy/errors 100 100 100 100
🟢   ...ationError.ts 100 100 100 100
🟢  proxy/handlers 97.72 96.42 100 97.67
🟢   ingress.ts 100 100 100 100
🟢   status.ts 95.45 91.66 100 95.23 119
🔴  proxy/http 0 100 0 0
🔴   responses.ts 0 100 0 0 6
🟢  proxy/utils 96.18 92.3 100 96.09
🟢   cookies.ts 100 100 100 100
🟢   error.ts 100 50 100 100 2
🟢   errorResponse.ts 100 100 100 100
🟢   headers.ts 100 96.55 100 100 72
🟢   ip.ts 100 90 100 100 8
🟢   paths.ts 100 100 100 100
🟢   region.ts 100 100 100 100
🟢   request.ts 100 100 100 100
🟢   traffic.ts 100 100 100 100
🟢   transport.ts 83.87 80 100 83.87 59,91-96
🟡  shared 66.66 0 60 66.66
🔴   assert.ts 33.33 0 50 33.33 2-3
🟢   routing.ts 100 100 100 100
🟢   status.ts 100 100 100 100
🔴   version.ts 0 100 0 0 4
🟢  ...omer-variables 100 93.33 100 100
🟢   ...rVariables.ts 100 100 100 100
🟢   ...rVariables.ts 100 100 100 100
🟢   defaults.ts 100 100 100 100
🟢   ...teVariable.ts 100 100 100 100
🟢   selectors.ts 100 75 100 100 25
🟢   types.ts 100 100 100 100
🟢  shared/test 100 100 100 100
🟢   azure.ts 100 100 100 100

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused validation fix and effective regression assertions address the reported routing issue without any identified blocking issues.

No open issues 🎉

What changed in this PR

This PR hardens region validation in the Azure Front Door proxy so object prototype keys fall back to the default US region instead of producing invalid upstream hostnames.

Changes:

  • Validate regions against supported enum values and build hostnames from the validated result.
  • Add prototype-key regression coverage and move ingress URL assertions outside mocked requests so failures are observable.
  • Add a patch changeset.
File Description
proxy/​utils/​region.ts Restricts validation to supported region values.
proxy/​utils/​region.test.ts Tests valid regions and fallback for invalid values and prototype keys.
proxy/​handlers/​ingress.ts Uses the validated region for the hostname prefix.
proxy/​handlers/​ingress.test.ts Adds prototype-key cases and fixes URL assertion placement.
proxy/​handlers/​ingress_v4.test.ts Applies the same regression checks to V4 ingress.
.changeset/​region-prototype-keys.md Documents the routing fix for a patch release.

Review effort: Balanced

@JuroUhlar
JuroUhlar merged commit b7656cb into main Oct 27, 2026
18 of 20 checks passed
@JuroUhlar
JuroUhlar deleted the fix/region-prototype-keys branch October 27, 2026 15:53
@JuroUhlar JuroUhlar changed the title fix: reject prototype keys in region validation INTER-2613: fix: reject prototype keys in region validation Oct 28, 2026

This branch was previously deployed

1 inactive deployment
dev — dfe9ae7c Deployed Oct 27, 2026 by JuroUhlar via E2E #268
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.

4 participants