Skip to content

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

Merged
vbudhram merged 1 commit into
mainfrom
fxa-14395
Sep 3, 2026
Merged

fix(auth-server): report the real Joi error for response validation#21104
vbudhram merged 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

This comment was marked as outdated.

## 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

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 implementation addresses the constraint collision with focused coverage; only a minor grammar correction remains.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

afterEach(() => {
mockReportValidationError.mockClear();
});
// 64 characters clears the token branch's length check, so both branches
@vbudhram

vbudhram commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

These changes are good too

@vbudhram
vbudhram merged commit 4ed9773 into main Sep 3, 2026
21 checks passed
@vbudhram
vbudhram deleted the fxa-14395 branch September 3, 2026 16:27
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.

4 participants