Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Allow enums inSignatureHasher::computeSignatureHash()#60302

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
BenMorel wants to merge3 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromBenMorel:signature_hasher_enum

Conversation

BenMorel
Copy link
Contributor

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT

Currently, usingremember_me.signature_properties on a property holding an enum fails with:

The property path "status" on the user object "App\Security\SecurityUser" must return a value that can be cast to a string, but "App(...)\UserStatus" was returned.

We can add support for enums in one of three ways:

  1. support all enums, and use the enum case name
  2. support only backed enums, and use the enum case backing value (int|string)
  3. support all enums, and use enum case name + backing value if available (most sensitive to changes)

In the current PR I went with option 2, but I'm thinking that option 3 could be better:

Pros:

  • it would support all enums
  • it would detect changes such as exchanging values of 2 enum cases

Cons:

  • it would invalidate the token if an enum case is renamed

I would welcome feedback here.

Aerendir reacted with rocket emoji
@derrabus
Copy link
Member

Tests? 🙃

@OskarStarkOskarStark changed the titleAllow enums in SignatureHasher::computeSignatureHash()Allow enums inSignatureHasher::computeSignatureHash()Apr 30, 2025
@carsonbotcarsonbot changed the titleAllow enums inSignatureHasher::computeSignatureHash()[Security] Allow enums inSignatureHasher::computeSignatureHash()Apr 30, 2025
@stof
Copy link
Member

Only option 2 makes sense to me. If you need your enum to have a canonical scalar representation, you should use a backed enum (that's what they are about).

  • it would detect changes such as exchanging values of 2 enum cases

that's not something we need to detect IMO (your DB would also have issues in such case, and this would require an insane architecture IMO)

@BenMorel
Copy link
ContributorAuthor

Alright then, thanks for your input,@stof.
@derrabus I'll add tests for the signature hasher, I was actually surprised to find none.

@BenMorelBenMorelforce-pushed thesignature_hasher_enum branch 3 times, most recently from5c6d8d2 to554fb1fCompareMay 21, 2025 11:34
@BenMorelBenMorelforce-pushed thesignature_hasher_enum branch from554fb1f to8b14913CompareMay 21, 2025 12:09
@BenMorelBenMorelforce-pushed thesignature_hasher_enum branch from3815106 tod13454cCompareMay 21, 2025 12:38
@BenMorel
Copy link
ContributorAuthor

@chalasr@derrabus@stof Ready for review.

I've split the PR into 3 commits:

  • Commit 1 adds the feature, and adds missing tests forSignatureHasher.
    As you can see, tests are rather ugly as in its current state,SignatureHasher uses a hardcoded combination ofhash_*() functions,base64_encode() andstrtr(), with no mechanism in place to mock these:
    ['someValue', ['arbitraryValue'],'kfMzZgYYD1oeqSSW7m0k94VuRvS7LeHcKq-PKU8WD7k~0nuV8X2IlHqxDdPRNOLP-wp_v2KdVL9dNYJ0_557fGc~'],['someValue', ['identifier','arbitraryValue'],'myxvvho8WkMuOcMMeuRlZQFe58TNDQFgDrVFb8SZ50g~iJ4d_Agaa0AaCHZinVr_zZCgR2nSZgokvXIkv7ne1b4~'],
  • Commit 2 proposes introducingHasherInterface andHashContextInterface, which are now mockable, and allow to see what is hashed exactly in tests:
    - ['someValue', ['arbitraryValue'], 'kfMzZgYYD1oeqSSW7m0k94VuRvS7LeHcKq-PKU8WD7k~0nuV8X2IlHqxDdPRNOLP-wp_v2KdVL9dNYJ0_557fGc~'],- ['someValue', ['identifier', 'arbitraryValue'], 'myxvvho8WkMuOcMMeuRlZQFe58TNDQFgDrVFb8SZ50g~iJ4d_Agaa0AaCHZinVr_zZCgR2nSZgokvXIkv7ne1b4~'],+ ['someValue', ['arbitraryValue'], true, 'HMAC(HASH(:someValue):1234567890:username,s3cr3t)HASH(:someValue)'],+ ['someValue', ['identifier', 'arbitraryValue'], true, 'HMAC(HASH(:username:someValue):1234567890:username,s3cr3t)HASH(:username:someValue)'],
  • Commit 3 fixes a missing dependency onsymfony/property-access, highlighted by the newly added tests forSignatureHasher.

@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@BenMorel@derrabus@stof@fabpot@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp