-
Notifications
You must be signed in to change notification settings - Fork 128
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] Ensure we have a valid csrf token when making POST requests in 10-10CG #34395
base: main
Are you sure you want to change the base?
Conversation
}); | ||
}; | ||
|
||
export const ensureValidCSRFToken = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic we had in the fetchFacilities
, just moved it here so it can be reused. Maybe there is a better place than actions? It's really a helper, but I'm also hoping it does not stay here super long as we will want to eventually get it somewhere more global.
@@ -155,69 +141,6 @@ describe('CG fetchFacilities action', () => { | |||
expect(apiRequestStub.callCount).to.equal(1); | |||
}); | |||
}); | |||
|
|||
context('no csrfToken in localStorage', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all tested in the unit spec for the new ensureValidCSRFToken
There was a problem hiding this 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.
event: 'caregivers-10-10cg-fetch-csrf-token-empty', | ||
}); | ||
|
||
Sentry.withScope(scope => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
}); | ||
|
||
Sentry.withScope(scope => { | ||
scope.setLevel(Sentry.Severity.Log); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
|
||
Sentry.withScope(scope => { | ||
scope.setLevel(Sentry.Severity.Log); | ||
Sentry.captureMessage(`${message} Calling ${url} to generate new one.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
|
||
return apiRequest(`${environment.API_URL}${url}`, { method: 'HEAD' }) | ||
.then(() => { | ||
Sentry.withScope(scope => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
return apiRequest(`${environment.API_URL}${url}`, { method: 'HEAD' }) | ||
.then(() => { | ||
Sentry.withScope(scope => { | ||
scope.setLevel(Sentry.Severity.Log); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
.then(() => { | ||
Sentry.withScope(scope => { | ||
scope.setLevel(Sentry.Severity.Log); | ||
Sentry.captureMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
}); | ||
}) | ||
.catch(error => { | ||
Sentry.withScope(scope => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
}) | ||
.catch(error => { | ||
Sentry.withScope(scope => { | ||
scope.setLevel(Sentry.Severity.Log); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
Sentry.withScope(scope => { | ||
scope.setLevel(Sentry.Severity.Log); | ||
scope.setExtra('error', error); | ||
Sentry.captureMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry found
Note: Delete the description statements, complete each step. None are optional, but can be justified as to why they cannot be completed as written. Provide known gaps to testing that may raise the risk of merging to production.
Are you removing, renaming or moving a folder in this PR?
If the folder you changed contains a
manifest.json
, search for itsentryName
in the content-build registry.json (theentryName
there will match).If an entry for this folder exists in content-build and you are:
Deleting a folder:
vets-website
for all instances of theentryName
in yourmanifest.json
and remove them in a separate PR. Look particularly for references insrc/applications/static-pages/static-pages-entry.js
andsrc/platform/forms/constants.js
. If you do not do this, other applications will break!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).
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
HEAD
request to generate a new csrf token when it is absent from localStorage in thefetchFacilities
function.ensureValidCSRFToken
function that checks if the csrf token is in local storage, and if it is not it makes theHEAD
request to generate a new one.fetchFacilities
function and in theApplicationDownloadLink
component that makes aPOST
call to generate a pdf for download.apiRequest
function.ApplicationDownloadLink
since we have consistently been seeing 403 invalid csrf errors for years on this call, and I think getting it in to validate it here sooner is better than waiting to ensure we have the right approach to introduce it sitewide via theapiRequest
function.Related issue(s)
Testing done
Screenshots
No UI changes
What areas of the site does it impact?
10-10CG
Acceptance criteria
Quality Assurance & Testing
Error Handling
Authentication