Repository navigation
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-203/ This page is automatically updated on each push to this PR. |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-203/ This page is automatically updated on each push to this PR. |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-203/ This page is automatically updated on each push to this PR. |
First step of adding CSRF protection to the session-authenticated admin API. The frontend must send the token before the routes enforce it. - layout.blade.php: expose <meta name="csrf-token"> to the legacy jQuery pages - ajax.utils.js: jQuery ajaxPrefilter adding X-CSRF-TOKEN to same-origin state-changing requests (never cross-origin, never GET/HEAD/OPTIONS) - profile/actions.js: save() passed the token as a query parameter instead of a header (putRawRequest args are payload, params, headers) - server-config.blade.php: add the _token field to the native POST form - tests/js/csrf_token.test.js: cover the header position and the prefilter
Several actions passed the token in an argument that is not the headers
of the base_actions helper, so it never reached X-CSRF-TOKEN and the call
would answer 419 once the admin routes enforce csrf:
- regenerateClientSecret: putRawRequest(payload, params, headers) got the
token as payload, so it went out as a JSON body field
- addClient, addPublicKey: postRawRequest takes (params, headers); the
extra {} became the headers and the token was dropped
- profile and admin edit-user picture upload: putFile(file, name,
fileMetadata, headers) got the token as fileMetadata, a multipart field
tests/js/csrf_actions.test.js mocks superagent and checks, for every
mutating admin/profile action, that X-CSRF-TOKEN is sent as a header and
never in the body, URL or multipart fields. It fails on 5 actions before
this change.
profile/actions revokeToken and revokeAllTokens read window.CSFR_TOKEN, which only profile.blade.php and edit-client.blade.php set. The admin Edit User page reuses revokeToken but never sets that global, so it sent "X-CSRF-TOKEN: undefined" and revoking a user's access token would answer 419 once admin/api/v1 enforces csrf. Both actions now take the token from the caller; the profile and admin edit-user pages pass their csrfToken prop. The Jest test covers both actions with window.CSFR_TOKEN unset.
c8b1cd0 to
a413ad0
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-203/ This page is automatically updated on each push to this PR. |
ref: https://app.clickup.com/t/9014802374/1k5eh578t2z
Context
PR 1 of 2 for ClickUp 1k5eh578t2z (CSRF protection for the session-authenticated admin API). The frontend has to send the token before the backend starts enforcing it, so this PR is safe to deploy on its own: it only sends an extra header to routes that do not check it yet. PR 2 (the
csrfmiddleware on the routes, plus tests with the middleware enabled) is stacked on top of this one and must not ship before it.Changes
layout.blade.php: expose<meta name="csrf-token">to the 15 legacy jQuery views (those onreactapp_layoutalready declare it).public/assets/js/ajax.utils.js: global jQueryajaxPrefilterthat addsX-CSRF-TOKENto same-origin state-changing requests. It is never added to GET/HEAD/OPTIONS or cross-origin requests.resources/js/profile/actions.js:save()passed the token as a query parameter instead of a header (putRawRequesttakes payload, params, headers). Withcsrfenforced this would have returned 419.server-config.blade.php: add@csrfto the native POST form.tests/js/csrf_token.test.js: 6 Jest tests (header position, prefilter on POST/PUT/DELETE, not on GET, not cross-origin). The 4 that cover the new behavior fail without the change.Token passed in the wrong argument of the
base_actionshelpers, so it never reached theX-CSRF-TOKENheader (found in review of fix(csrf): require the CSRF token on the session-authenticated admin routes #204):edit_clientregenerateClientSecret: sent as the JSON payload ofputRawRequest.clientsaddClientandedit_clientaddPublicKey:postRawRequesttakes(params, headers); the extra{}became the headers and the token was dropped.profileandadmin/edit_userpicture upload: sent asfileMetadataofputFile, i.e. a multipart field.profilerevokeToken/revokeAllTokensreadwindow.CSFR_TOKEN, which the admin Edit User page (which reusesrevokeToken) never sets, so it sentX-CSRF-TOKEN: undefined. Both now take the token from the caller (csrfTokenprop).tests/js/csrf_actions.test.js: mocks superagent and checks, for every mutating admin/profile React action (15), that the token goes out as a header and never in the body, URL or multipart fields. Fails on 5 actions before the fix, plus a case withwindow.CSFR_TOKENunset for the revocation actions.Testing
npx jest tests/js/csrf_token.test.js tests/js/csrf_actions.test.js: 38 passed.tests/js/turnstile_*suites fail to run locally because@testing-library/reactis missing fromnode_modules(unrelated to this change).