Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent 500s from malformed requests in crumb generation #676

Merged
merged 4 commits into from
Jan 23, 2025

Conversation

mokhld
Copy link
Contributor

@mokhld mokhld commented Jan 23, 2025

Summary of Attempted Solutions That Didn't Work:

  1. Yar Configuration

    • Tried enabling storeBlank: true in session plugin
    • Didn't resolve the state initialisation timing issue and there's the issue of it breaking our auth tests mentioned in the comment
  2. Crumb Plugin Changes

    • Added skip function with state checks
    • Added try/catch and defensive checks
    • Still hit errors before skip function was called

Root Issue:
The error occurs because crumb tries to access request.state before Yar has a chance to initialise it

crumb:
request?.server.plugins.crumb.generate &&
request.route.settings.plugins?.crumb !== false &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Copy link
Contributor Author

@mokhld mokhld Jan 23, 2025

Choose a reason for hiding this comment

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

I attempted to mark as optional in Hapi type definitions but it can't seem be overridden, and can be undefined for malformed requests hence the 500s (see here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also make this more defensive if needed but it's scalability is questionable e.g.

 request?.state &&
!request.path.includes('//')

@mokhld mokhld marked this pull request as ready for review January 23, 2025 12:14
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
84.6% Coverage on New Code (required ≥ 90%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@alexluckett alexluckett left a comment

Choose a reason for hiding this comment

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

Thank you 🙌

@mokhld mokhld merged commit c8859c5 into main Jan 23, 2025
10 of 11 checks passed
@mokhld mokhld deleted the fix/no-ticket-crumb branch January 23, 2025 15:37
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