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

Skip to content

Hide sensitive information with SensitiveParameter attribute #46183

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
Jul 11, 2022

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Apr 27, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets n/a
License MIT
Doc PR n/a

New feature for PHP 8.2: Redact parameters in back traces

This could be a "minor" change, but I think it should be highlighted to be fully functional. The annotation is required in all calling functions otherwise the argument value is displayed.

@GromNaN GromNaN requested a review from chalasr as a code owner April 27, 2022 06:57
@carsonbot carsonbot added this to the 6.1 milestone Apr 27, 2022
@carsonbot carsonbot changed the title [PasswordHasher] Hide sensitive information from stack traces with SensitiveParameter attribute [PasswordHasher] Hide sensitive information from stack traces with SensitiveParameter attribute Apr 27, 2022
@GromNaN GromNaN modified the milestones: 6.1, 6.2 Apr 27, 2022
6.2
---

* Hide sensitive information from stack traces with `SensitiveParameter` attribute
Copy link
Member Author

Choose a reason for hiding this comment

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

Added the info to the changelog for discoverability.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to be more precise about "Hide". It's "only" for back traces.

@@ -29,12 +29,12 @@ interface PasswordHasherInterface
*
* @throws InvalidPasswordException When the plain password is invalid, e.g. excessively long
*/
public function hash(string $plainPassword): string;
public function hash(#[\SensitiveParameter] string $plainPassword): string;
Copy link
Member Author

Choose a reason for hiding this comment

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

The attribute has no effect on the interface, but is a remainder for implementers.

@GromNaN GromNaN changed the title [PasswordHasher] Hide sensitive information from stack traces with SensitiveParameter attribute [PasswordHasher] Hide sensitive information with SensitiveParameter attribute Apr 27, 2022
@javiereguiluz
Copy link
Member

Just saying: in the PHP repository there was an issue about making this #[\SensitiveParameter] feature configurable because in dev/test you probably don't want to hide anything.

See php/php-src#8381

@GromNaN
Copy link
Member Author

GromNaN commented Apr 28, 2022

@javiereguiluz we should expose the SensitiveParameterValue in Symfony error page and profiler?

@javiereguiluz
Copy link
Member

I don't know. It was just a "maybe we should think about this" comment.

Imagine a bug where you mistyped some chars in your password. But is that common?

@chalasr
Copy link
Member

chalasr commented Jul 5, 2022

Can you take a look at the rest of the codebase where this could be useful? I think it's fine do it once for all, everywhere plain credentials are passed around (#46853 mentions some relevant places btw)

@TimWolla
Copy link
Contributor

TimWolla commented Jul 5, 2022

RFC author here 👋

Can you take a look at the rest of the codebase where this could be useful? I think it's fine do it once for all, everywhere plain credentials are passed around

I recommend not just looking at credentials, but also stuff like plaintext values that are passed into an encryption component to be encrypted. I'm not a Symfony user, but an example would likely be CsrfTokenManager::randomize().

My php-src PR that adds the attribute is this one: php/php-src#8352, it might be a good reference.

@GromNaN GromNaN force-pushed the sensitive-parameter branch from 36389dc to 64609b9 Compare July 9, 2022 21:55
@GromNaN GromNaN force-pushed the sensitive-parameter branch from 64609b9 to a57746d Compare July 9, 2022 22:07
@GromNaN
Copy link
Member Author

GromNaN commented Jul 9, 2022

I added the attribute on every parameter that looks like a secret.

Notes:

  • A DSN string can contain the password. Hiding the whole DSN can hurt debugging.
  • Some functions cannot throw an exception or make an error. Adding the annotation may be useless.
  • This attribute is not a guarantee that a sensitive value will not be exposed. This values are passed to generic functions that will not have the attribute.

@GromNaN GromNaN changed the title [PasswordHasher] Hide sensitive information with SensitiveParameter attribute Hide sensitive information with SensitiveParameter attribute Jul 9, 2022
@chalasr
Copy link
Member

chalasr commented Jul 10, 2022

A DSN string can contain the password. Hiding the whole DSN can hurt debugging.

That's ok as long as we manage to reveal the sensitive values in debugging contexts such as the webprofiler, right?

Some functions cannot throw an exception or make an error. Adding the annotation may be useless.

Fine to me as well, as they might do at some point or be extended.

6.2
---

* Hide sensitive information from stack traces with `SensitiveParameter` attribute
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to be more precise about "Hide". It's "only" for back traces.

@fabpot
Copy link
Member

fabpot commented Jul 11, 2022

Thank you @GromNaN.

@fabpot fabpot force-pushed the sensitive-parameter branch from b13a5e4 to 7dcc4ac Compare July 11, 2022 06:49
@fabpot fabpot merged commit 4a31363 into symfony:6.2 Jul 11, 2022
@GromNaN GromNaN deleted the sensitive-parameter branch July 11, 2022 07:15
@fabpot fabpot mentioned this pull request Oct 24, 2022
fabpot added a commit that referenced this pull request Nov 22, 2022
This PR was merged into the 6.2 branch.

Discussion
----------

Add more #[\SensitiveParameter]

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Follow-up to #46183

Commits
-------

8ad9642 Add more #[\SensitiveParameter]
nicolas-grekas added a commit that referenced this pull request Jan 19, 2023
This PR was merged into the 6.3 branch.

Discussion
----------

Add #[\SensitiveParameter] to $sessionId

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Follow-up to #48274 and #46183

Commits
-------

32c9f28 Add #[\SensitiveParameter] to $sessionId
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.

6 participants