Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Fix notice when HTTP_PHP_AUTH_USER passed without pass #44759

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

Merged
merged 1 commit into from
Dec 28, 2021

Conversation

vitman
Copy link

@vitman vitman commented Dec 21, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? No
Deprecations? No
License MIT

There is a way to pass HTTP_XXX vars. If someone will pass HTTP_PHP_AUTH_USER var without HTTP_PHP_AUTH_PW notice will appear since there is no second isset check against $headers, there is isset only for $this->params

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@vitman vitman force-pushed the patch-2 branch 4 times, most recently from 38b722f to c7a09d5 Compare December 21, 2021 22:33
@fabpot
Copy link
Member

fabpot commented Dec 22, 2021

I have a mixed feeling about this one. PHP_AUTH_PW should always be set when using PHP_AUTH_USER. So, I would rather fix your code instead.

@vitman
Copy link
Author

vitman commented Dec 22, 2021

But it's not mine code ¯_(ツ)_/¯
The case is: someone scanning my app with invalid headers and I getting notices in logs. Then params are being validated and rejected properly(or not being used at all), but it's weird when vendor's code(Request::createFromGlobals()) produce notices.

Moreover, if PHP_AUTH_PW should always be set, why do we have isset check on line 41 (instead of exception for example)?

I guess it worth to make behavior consistent. So either remove ?? on line 41 or add ?? for $headers.

@fabpot what do you think?

@stof
Copy link
Member

stof commented Dec 22, 2021

PHP_AUTH_USER is not supposed to be an HTTP header (accessible through HTTP_PHP_AUTH_USER in the PHP superglobals). I think

if (isset($this->parameters['PHP_AUTH_USER'])) {
$headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER'];
$headers['PHP_AUTH_PW'] = $this->parameters['PHP_AUTH_PW'] ?? '';
} else {
should store those in local variables, not in the $headers array.

Same for PHP_AUTH_DIGEST later in the method

@wouterj
Copy link
Member

wouterj commented Dec 22, 2021

PHP_AUTH_USER is not supposed to be an HTTP header (accessible through HTTP_PHP_AUTH_USER in the PHP superglobals). I think [...] should store those in local variables, not in the $headers array.

Seems like this was introduced as a workaround for fastcgi with Apache in 2.0: #3551 & symfony/symfony-docs#2529

If we were to refactor this, we should probably take care not to break this workaround? (tbh unless this is a critical fix, I would favor not rewriting this 10 year old code, which is the only way to make sure we don't unintentionally break things)

@stof
Copy link
Member

stof commented Dec 22, 2021

the Apache workaround was adding the support for HTTP_AUTHORIZATION in the else clause. This does not require storing the PHP_AUTH_* values as part of the headers (and as such allowing them to be provided as header by a crafted request too)

@nicolas-grekas nicolas-grekas changed the title Notice when HTTP_PHP_AUTH_USER passed without pass Fix notice when HTTP_PHP_AUTH_USER passed without pass Dec 25, 2021
@carsonbot carsonbot changed the title Fix notice when HTTP_PHP_AUTH_USER passed without pass [HttpFoundation] Fix notice when HTTP_PHP_AUTH_USER passed without pass Dec 25, 2021
@@ -89,6 +89,7 @@ public function getHeaders()

// PHP_AUTH_USER/PHP_AUTH_PW
if (isset($headers['PHP_AUTH_USER'])) {
$headers['PHP_AUTH_PW'] = $headers['PHP_AUTH_PW'] ?? '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not store the empty string as suggested by stof.
using ($headers['PHP_AUTH_PW'] ?? '') on the line below should be enough

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@vitman
Copy link
Author

vitman commented Dec 27, 2021

@stof @nicolas-grekas @fabpot simplified this one by following Nicolas suggestion. Let's make some decision :)

@fabpot
Copy link
Member

fabpot commented Dec 28, 2021

Thank you @vitman.

@fabpot fabpot merged commit 4987fd1 into symfony:4.4 Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants