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

[10-10CG] Reset csrfToken on 403 response for fetchFacilities #34431

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

coope93
Copy link
Contributor

@coope93 coope93 commented Jan 31, 2025

Are you removing, renaming or moving a folder in this PR?

  • No, I'm not changing any folders (skip to TeamSites and delete the rest of this section)
  • Yes, I'm removing, renaming or moving a folder

If the folder you changed contains a manifest.json, search for its entryName in the content-build registry.json (the entryName there will match).

If an entry for this folder exists in content-build and you are:

  1. Deleting a folder:

    1. First search vets-website for all instances of the entryName in your manifest.json and remove them in a separate PR. Look particularly for references in src/applications/static-pages/static-pages-entry.js and src/platform/forms/constants.js. If you do not do this, other applications will break!
      • Add the link to your merged vets-website PR here
    2. Then, Delete the application entry in registry.json and merge that PR before this one
      • Add the link to your merged content-build PR here
  2. Renaming or moving a folder: Update the entry in the registry.json, but do not merge it until your vets-website changes here are merged. The content-build PR must be merged immediately after your vets-website change is merged in to avoid CI errors with content-build (and Tugboat).

⚠️ TeamSites ⚠️

Examples of a TeamSite: https://va.gov/health and https://benefits.va.gov/benefits/. This scenario is also referred to as the "injected" header and footer. You can reach out in the #sitewide-public-websites Slack channel for questions.

Did you change site-wide styles, platform utilities or other infrastructure?

Summary

  • We have consistently been seeing 403 Invalid Authenticity Token in our new facilities search page. The last two appear to have tried to pass invalid csrf tokens from the client.
  • This change checks the response, and if the error response was a 403 - Invalid Authenticity Token error we set the csrfToken in localStorage to an empty string. If the request is retried, it will trigger the logic that checks if there is a token, and if not it makes a HEAD request to ensure it has a valid token, which then calls the fetchFacilities with a valid token.
  • 1010 Health Apps
  • This work is behind the caregiver_use_facilities_API toggle

Related issue(s)

Testing done

  • Updated unit specs
  • Manual testing in RI

Screenshots

No UI changes

Before After
Mobile
Desktop

What areas of the site does it impact?

10-10CG

Acceptance criteria

Quality Assurance & Testing

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Linting warnings have been addressed
  • Documentation has been updated (link to documentation *if necessary)
  • Screenshot of the developed feature is added
  • Accessibility testing has been performed

Error Handling

  • Browser console contains no warnings or errors.
  • Events are being sent to the appropriate logging solution
  • Feature/bug has a monitor built into Datadog or Grafana (if applicable)

Authentication

  • Did you login to a local build and verify all authenticated routes work as expected with a test user

@@ -125,10 +125,27 @@ export const fetchFacilities = async ({
})
.catch(error => {
Sentry.withScope(scope => {
scope.setExtra('error', error);
scope.setExtra('error', error.errors);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This errors object was just showing

{
 errors: [
   [Object]
 ]
}

Which is not helpful. This will instead show the error array which has more detail.


if (
errorResponse?.status === '403' &&
errorResponse?.detail === 'Invalid Authenticity Token'
Copy link
Contributor Author

@coope93 coope93 Jan 31, 2025

Choose a reason for hiding this comment

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

I only want to trigger this for 403s AND when it is an Invalid Authenticity Token, since there are other valid 403 responses we don't want to trigger this logic.

scope.setExtra('status', errorResponse?.status);
scope.setExtra('detail', errorResponse?.detail);
Sentry.captureMessage(
'Error in fetchFacilities. Clearing csrfToken in localStorage.',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new Sentry log so we know when these occur and give us more detail into what's going on.

@coope93 coope93 self-assigned this Jan 31, 2025
@coope93 coope93 marked this pull request as ready for review January 31, 2025 17:21
@coope93 coope93 requested review from a team as code owners January 31, 2025 17:21
Copy link

@va-vfs-bot va-vfs-bot left a comment

Choose a reason for hiding this comment

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

Sentry call found

Sentry captures a lot of data, and we want to make sure that we only keep information that will be useful for troubleshooting issues. This means that PII should not be recorded.

What you can do

Review your call to Sentry and see if you can reasonably reduce any information that is included, or wait for a VSP review.

@coope93 coope93 merged commit c2613c5 into main Jan 31, 2025
75 checks passed
@coope93 coope93 deleted the coope93-reset-csrf-token-on-403-facilities-fetch branch January 31, 2025 21:14
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.

3 participants