Repository navigation
COG-1160: W1 AdminPortal XSRF-TOKEN plumbing (trailing-slash audit: no changes needed) #344
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Headers, RequestOptionsArgs } from '@angular/http'; | ||
|
|
||
| export const XSRF_COOKIE_NAME = 'XSRF-TOKEN'; | ||
| export const XSRF_HEADER_NAME = 'X-XSRF-TOKEN'; | ||
|
|
||
| export function readXsrfToken(): string { | ||
| const match = document.cookie.match(new RegExp('(?:^|;\\s*)' + XSRF_COOKIE_NAME + '=([^;]*)')); | ||
| return match ? decodeURIComponent(match[1]) : null; | ||
| } | ||
|
|
||
| // The header is only added when the cookie exists: a custom header forces a CORS preflight. | ||
| export function xsrfHeaders(headers: Headers = new Headers()): Headers { | ||
| const token = readXsrfToken(); | ||
| if (token) { | ||
| headers.set(XSRF_HEADER_NAME, token); | ||
|
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Existing XSRF cookie blocks admin login When localhost has an Learn moreThe AdminPortal runs at localhost:4200 and posts credentials to localhost:8080, so its requests are cross-origin. The existing RequestFilter answers OPTIONS requests without permitting Example: A different localhost application previously set Recommended fix: Coordinate the header rollout with an update to Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does happen, and it's a known edge case of the design the audit prescribes (COG-1147 item M6). Adding the header only when the cookie exists is what keeps it from firing on a clean browser against the 1.5.4 server. The real fix is the one you point to: allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up from browser testing: this already happens on master. Angular 4 |
||
| } | ||
| return headers; | ||
| } | ||
|
|
||
| export function xsrfOptions(headers?: Headers): RequestOptionsArgs { | ||
| return { headers: xsrfHeaders(headers), withCredentials: true }; | ||
| } | ||
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.
🔍 Bootstrap failures are invisible to login
fetchCsrfTokenconverts every GET error into a value, then attempts login. Once token issuance depends on that GET, the login UI cannot distinguish a bootstrap failure from a rejected login.Was this helpful? React with 👍 or 👎 to provide feedback.
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 intentional. The bootstrap GET is best-effort, and a failure there shouldn't stop the login attempt: while server CSRF is off, the POST works without a token. Once COG-1166 turns CSRF on, a failed bootstrap means the POST goes out without
X-XSRF-TOKEN, the server rejects it with 403, and that error reachesLoginComponent'serrcallback. So the failure does surface, just as a failed login. I'm not adding a separate error state for the bootstrap here, because it would change the login component's UX, which is outside this ticket.