Skip to content

fix(auth-server): report the real Joi error for response validation - #21104

Open
vbudhram wants to merge 1 commit into
mainfrom
fxa-14395
Open

fix(auth-server): report the real Joi error for response validation#21104
vbudhram wants to merge 1 commit into
mainfrom
fxa-14395

Conversation

@vbudhram

@vbudhram vbudhram commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Because

  • flattenValidationDetails keyed its dedup map on path and Joi type alone. Two different constraints on one path overwrote each other.
  • accessToken is an alternatives() of two string patterns, so both branches report string.pattern.base on the same path. Only the second one survived, and the fingerprint could not tell a hex-token failure from a JWT failure.
  • So the grouping problem this PR set out to fix came back one level down.

This pull request

  • Adds a constraint field to each flattened leaf, taken from detail.context.regex.source.
  • Keys the dedup map and the Sentry fingerprint on path:type:constraint, so the two patterns stay apart.
  • Builds the spec fixture from the production accessToken validator in lib/oauth/validators.js, so the test covers the real colliding patterns.

Issue that this pull request solves

Closes: https://mozilla-hub.atlassian.net/browse/FXA-14395

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

How to review (Optional)

  • Key files/areas to focus on: flattenValidationDetails in packages/fxa-auth-server/lib/server.js.
  • Suggested review order: server.js, then server.in.spec.ts.
  • Risky or complex parts: none. failAction and redactValue have zero diff, and the array-index collapse still groups items[0] and items[3] as one entry.

Screenshots (Optional)

Other information (Optional)

  • The review suggested ?? detail.context?.name as a second fallback. I left it out. In Joi, name appears only on string.pattern.name, and that context always carries regex too (joi/lib/types/string.js:571), so the branch never runs. I will add it back if you want it as a guard.
  • Limit constraints can still collide, for example string.max(3) against string.max(5) on one path. context.limit is the obvious discriminator, but it can be a Joi.ref() that resolves from the response payload, which would put a value in Sentry. That needs its own ticket.
  • Local runs: npx jest packages/fxa-auth-server/lib/server.in.spec.ts: 63 passed, 0 failed. npx nx lint fxa-auth-server: clean.

@vbudhram
vbudhram requested a review from a team as a code owner August 25, 2026 14:34
Copilot AI balanced review requested due to automatic review settings August 25, 2026 14:34
@vbudhram vbudhram added the auto label Aug 25, 2026

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.

Pull request overview

Improves auth-server response-validation diagnostics in Sentry while redacting response values.

Changes:

  • Flattens nested Joi validation details and normalizes array indexes.
  • Adds sanitized Sentry context, messages, and fingerprints.
  • Expands validation-reporting tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/fxa-auth-server/lib/server.js Implements flattened, redacted Sentry reporting.
packages/fxa-auth-server/lib/server.in.spec.ts Tests reporting, fingerprinting, and redaction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/fxa-auth-server/lib/server.js Outdated
Comment on lines +75 to +78
leaves.set(`${path}:${detail.type}`, {
path,
type: detail.type,
message: redactValue(detail.message, detail.context?.value),
## Because

- `flattenValidationDetails` keyed its dedup map on path and Joi type alone. Two different constraints on one path overwrote each other.
- `accessToken` is an `alternatives()` of two string patterns, so both branches report `string.pattern.base` on the same path. Only the second one survived, and the fingerprint could not tell a hex-token failure from a JWT failure.
- So the grouping problem this PR set out to fix came back one level down.

## This pull request

- Adds a `constraint` field to each flattened leaf, taken from `detail.context.regex.source`.
- Keys the dedup map and the Sentry fingerprint on `path:type:constraint`, so the two patterns stay apart.
- Builds the spec fixture from the production `accessToken` validator in `lib/oauth/validators.js`, so the test covers the real colliding patterns.

## Issue that this pull request solves

Closes: https://mozilla-hub.atlassian.net/browse/FXA-14395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants