Repository navigation
#115 Users: generate the API token with a POST request and a CSRF token - #116
Draft
njoubert-cleverage wants to merge 1 commit into
Draft
njoubert-cleverage wants to merge 1 commit into
njoubert-cleverage wants to merge 1 commit into
Conversation
The "generateToken" action was a link: a simple GET request (forged link, image…) replaced the API token of a user. It is now a POST form with a CSRF token per user and a confirmation; the route only accepts POST. The token is generated with random_bytes() (was md5(uniqid(date()))). BC break for the direct GET URL, see UPGRADE.md v4.0. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #115. Milestone v4.0 (BC break, see below).
UserCrudController:linkToUrl(),csrfTokenquery parameter), rendered as a POST form (renderAsForm()) with a confirmation (askConfirmation(): "The current API token of this user will no longer work.")#[AdminRoute]restricted to POST (GET: 405); the CSRF token is checked (403 otherwise)bin2hex(random_bytes(16))(32 hexadecimal characters, as before) instead ofmd5(uniqid(date('YmdHis')))Docs:
UPGRADE.mdv4.0, CHANGELOG underBC break.Tests:
UserCrudTest::testGenerateTokenRequiresAPostRequestWithACsrfToken: GET → 405, POST without / with an invalid CSRF token → 403, token unchangedUserCrudTest::testGenerateToken,HttpProcessExecuteTest::testTokenGeneratedInTheUi: the token is generated by submitting the form of the edit page (FunctionalTestCase::generateTokenInTheUi()), then used on the APIChecked:
Note:
UPGRADE.mdand the CHANGELOGBC breaksection are also added by #94 (milestone v4.0): the second merged PR will need a rebase.Requirements
Breaking changes
The direct
GET /process/user/{id}/generate-tokenURL no longer works (405): the token is generated from the button of the user edit page (seeUPGRADE.mdv4.0).🤖 Generated with Claude Code