-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Prevent PHP Warning: Session ID is too long or contains illegal characters #46790
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
Conversation
SessionHandler::read()
: Session ID is too long or contains illegal characters.)SessionHandler::read()
: Session ID is too long or contains illegal characters.)
@xabbuh Does the |
Hey! I think @BradJonesLLC has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
SessionHandler::read()
: Session ID is too long or contains illegal characters.)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.
I think this change is too strict and breaks legit use cases (typically when migrating from one set of settings to another).
The only required change is adding ,256
to me.
Hi @nicolas-grekas, If we only change the regular expression from On my windows, I can't set For example, in my case, the regular expression would have to check Or maybe we could just change the regular expression from What do you think? Do you have another solution to avoid the problem on Windows and Linux OS?
The code I suggest in this PR is a workaround that I use on my websites, and I have never encountered one problem so far. |
@nicolas-grekas I pushed a commit, changing only the regular expression, as you requested. But I set the max limit to 250 (see the comment above). |
…ins illegal characters
Thank you @brokensourcecode. |
Based on #46790 (comment) I have one question about this change: Wouldn't this now break applications on PHP installations having |
For reference, here is the validation logic in php-src: Note this comment there:
And here are some more notes about MAX_PATH: Based on that it looks like we should put 256 I agree with you @xabbuh: it's not our job to filter this as another layer will report the issue when there is one. |
@xabbuh That's why, since the start, I suggested to use the provided We can't use Solution 1: use
|
The problem we're trying to solve here is preventing a PHP warning. Being more strict than php itself is certainly not a solution to that problem. For this reason, using ini_get is no-go, since php itself doesn't use it to decide if the warning should be triggered or not (see link to php-src in my previous comment.) I accepted the argument to use 250 so that on Windows ppl don't hit MAX_PATH, but @xabbuh is right that this might break others' code. We should use 256 instead. |
You mean because on Windows this will generate notices related to MAX_PATH? |
I don't agree with you on that. I don't understand why trust the developer configuration is strict. If the developer does not know how to configure his application, he will know even less that this security problem exists.
I agree with you that 250 is not a relevant solution.
No. There are 2 cases: Case 1:
|
Great, that's exactly the warning I was wondering about. I also see a similar warning on Linux when the name of a file is 256 or longer. |
It seems that Windows and Linux OS limit filenames to 255 bytes ( |
@nicolas-grekas Maybe we should explain in the code why we use 250? By adding a comment that explains the calculation result? EDIT: done here #46825 |
…rceCode) This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Add session ID regex comment | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT A comment intended to explain the session ID regular expression. Related links: - #46777 - #46790 Commits ------- 4908090 [HttpFoundation] Add session ID regex comment
…rceCode) This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Add session ID regex comment | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT A comment intended to explain the session ID regular expression. Related links: - symfony/symfony#46777 - symfony/symfony#46790 Commits ------- 49080903d2 [HttpFoundation] Add session ID regex comment
This PR is intended to improve the changes made in the PR #46249 that doesn't check the max length of the session ID.
To do this, I used the PHP ini directives below:
session.sid_length
(must be an integer between22
and256
)session.sid_bits_per_character
(must be an integer such as4
,5
or6
)