Skip to content

Add #[\SensitiveParameter] to setApiKey() to prevent credential exposure#14

Draft
semgrep-code-badoo[bot] wants to merge 1 commit intomasterfrom
semgrep-autofix/1774439279
Draft

Add #[\SensitiveParameter] to setApiKey() to prevent credential exposure#14
semgrep-code-badoo[bot] wants to merge 1 commit intomasterfrom
semgrep-autofix/1774439279

Conversation

@semgrep-code-badoo
Copy link
Copy Markdown

Mark the $api_key parameter with #[\SensitiveParameter] attribute to prevent API key disclosure in stack traces.

Changes

  • Added #[\SensitiveParameter] attribute to the $api_key parameter in LiveProfiler::setApiKey()

Why

If the application crashes or throws an exception, PHP includes function parameters in stack traces and error logs by default. Without the #[\SensitiveParameter] attribute, the API key value would be exposed in these logs. This PHP 8.2+ attribute instructs PHP to redact the parameter value in backtraces, preventing unintended credential disclosure.

Semgrep Finding Details

Function parameter like $apiKey, $api_key, $accessKey, or $access_key contains sensitive credentials but is not marked with #[\SensitiveParameter]. If the application crashes or throws an exception, this value may be included in stack traces or error logs, leading to unintended API key disclosure. Add the #[\SensitiveParameter] attribute to prevent exposure.

@9071412 requested Semgrep Assistant generate this pull request to fix a finding.


⚠️ Review carefully before merging. This PR was generated by AI and may cause breaking changes or introduce new vulnerabilities.

Mark the `$api_key` parameter with `#[\SensitiveParameter]` attribute to prevent API key disclosure in stack traces.

## Changes
- Added `#[\SensitiveParameter]` attribute to the `$api_key` parameter in `LiveProfiler::setApiKey()`

## Why
If the application crashes or throws an exception, PHP includes function parameters in stack traces and error logs by default. Without the `#[\SensitiveParameter]` attribute, the API key value would be exposed in these logs. This PHP 8.2+ attribute instructs PHP to redact the parameter value in backtraces, preventing unintended credential disclosure.

## Semgrep Finding Details
Function parameter like $apiKey, $api_key, $accessKey, or $access_key contains sensitive credentials but is not marked with #[\SensitiveParameter]. If the application crashes or throws an exception, this value may be included in stack traces or error logs, leading to unintended API key disclosure. Add the #[\SensitiveParameter] attribute to prevent exposure.

@9071412 requested Semgrep Assistant generate this pull request to fix [a finding](https://semgrep.dev/orgs/bmbl/findings/695640277).
* @return $this
*/
public function setApiKey($api_key)
public function setApiKey(#[\SensitiveParameter] $api_key)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Semgrep identified an issue in your code:
Function parameter like $apiKey, $api_key, $accessKey, or $access_key contains sensitive credentials but is not marked with #[\SensitiveParameter]. If the application crashes or throws an exception, this value may be included in stack traces or error logs, leading to unintended API key disclosure. Add the #[\SensitiveParameter] attribute to prevent exposure.

To resolve this comment:

✨ Commit Assistant Fix Suggestion
  1. Add the sensitive parameter attribute above the setApiKey function by inserting #[\SensitiveParameter] on the line immediately before the function definition.
  2. The function definition should look like this: #[\SensitiveParameter] public function setApiKey($api_key)
  3. Make sure there is no docblock or comment line between the attribute and the function definition.

This attribute will help ensure that if an error or exception occurs, the value of $api_key will be protected from accidental exposure in error messages or stack traces.

💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by php-missing-sensitive-parameter-api-key.

You can view more details about this finding in the Semgrep AppSec Platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants