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] Return null instead of empty username to fix deprecation notice#59640

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

Merged
nicolas-grekas merged 1 commit intosymfony:6.4fromphasdev:fix_59584
Feb 5, 2025

Conversation

phasdev
Copy link
Contributor

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#59584
LicenseMIT

RemoteUserAuthenticator may return an empty string when extracting a username from the configured$_SERVER parameter (e.g.REMOTE_USER).

An empty username triggers theUser Deprecated: Since symfony/security-http 7.2: Using an empty string as user identifier is deprecated and will throw an exception in Symfony 8.0.

Returnnull instead of empty username to skip authenticator when username is empty and fix Symfony 8 deprecation notice.

AirBair reacted with thumbs up emoji
@@ -45,6 +45,6 @@ protected function extractUsername(Request $request): ?string
throw new BadCredentialsException(sprintf('User key was not found: "%s".', $this->userKey));
}

return $request->server->get($this->userKey);
return $request->server->get($this->userKey) ?: null;
Copy link
ContributorAuthor

@phasdevphasdevJan 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Looking at how the method is used I wonder if we shouldn’t throw a BadCredentialsException here then.
(xabbuh's comment on previous PR)

Copy link
ContributorAuthor

@phasdevphasdevJan 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Throwing an exception would be consistent with theFormLoginAuthenticator's behaviour :

if ('' ===$credentials['username']) {
thrownewBadCredentialsException(\sprintf('The key "%s" must be a non-empty string.',$this->options['username_parameter']));

OTOH the base class' abstractextractUsername() returns a nullable string and the null check insupports() indicates this is due to being unable to extract a username. Other users who've extended the base class may expect that behaviour, so throwing an exception (in a reference implementation) may be confusing.

abstractprotectedfunctionextractUsername(Request$request): ?string;

if (null ===$username) {
$this->logger?->debug('Skipping pre-authenticated authenticator no username could be extracted.', ['authenticator' =>static::class]);

chalasr reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to me

@phasdev
Copy link
ContributorAuthor

@nicolas-grekas,@xabbuh

Apologies; I ran into some trouble rebasing the commit for a test case from myprevious PR so I created a new branch/PR to be safe.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Works for me as is.

@nicolas-grekas
Copy link
Member

Thank you@phasdev.

@nicolas-grekasnicolas-grekas merged commit25dd52e intosymfony:6.4Feb 5, 2025
11 checks passed
This was referencedFeb 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@OskarStarkOskarStarkOskarStark approved these changes

@xabbuhxabbuhxabbuh approved these changes

@chalasrchalasrchalasr approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

6 participants
@phasdev@nicolas-grekas@OskarStark@xabbuh@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp