GHSA-hmqg-cxww-wqhq: OS Command Injection
Impact
PHPCodeSniffer versions before v3.13.6 and v4.0.2 contain a command injection vulnerability in the code creating the Gitblame, Hgblame and Svnblame report(s).
As a result, running PHPCodeSniffer over untrusted files, for example, in a CI pipeline that scans pull requests, or on a developer machine reviewing third-party code, could result in attacker-controlled shell commands being executed when the Gitblame, Hgblame or Svnblame report(s) would process a file whose name contains shell metacharacters.
Users using the default Full report, or any of the other non-blame reports, are not affected. Users on a runtime platform which does not allow filenames to contain shell metacharacters, such as " and ;, are not affected.
Patched versions
The issue has been fixed in PHPCodeSniffer v3.13.6 and v4.0.2. We recommend all users upgrade to these versions at their earliest convenience.
Workaround
Users of PHPCodeSniffer who cannot upgrade immediately should ensure they do not use the Gitblame, Hgblame or the Svnblame reports when scanning untrusted code.
This is especially relevant for CI jobs, pre-commit or review tooling, automated review services, and any service that scans untrusted repositories or uploaded source trees.
Credits
Many thanks to both @Faze-up and @edorian for responsibly disclosing this vulnerability.
How can I report a security bug?
Please report security vulnerabilities privately via the "Security and quality" tab on the PHPCodeSniffer repository.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/squizlabs/php_codesnifferto a version that resolves this vulnerability.Fixed in 4.0.2 - Upgrade
Upgrade
composer/squizlabs/php_codesnifferto a version that resolves this vulnerability.Fixed in 3.13.6 - Upgrade
Upgrade
PHP_CodeSnifferto a version that resolves this vulnerability.Fixed in 3.13.6 - Upgrade
Upgrade
PHP_CodeSnifferto a version that resolves this vulnerability.Fixed in 4.0.2 - Configuration
If you cannot upgrade, do not use the Gitblame, Hgblame, or Svnblame report(s) when scanning untrusted code; use other (non-blame) reports instead.
PHP_CodeSniffer Use of Gitblame/Hgblame/Svnblame reports = Do not use
Event History
Frequently Asked Questions
What is the severity of GHSA-hmqg-cxww-wqhq?
GHSA-hmqg-cxww-wqhq has a risk score of 60, indicating a moderate severity level.
How do I fix GHSA-hmqg-cxww-wqhq?
To fix GHSA-hmqg-cxww-wqhq, update PHP_CodeSniffer to version 3.13.6 or later, or version 4.0.2 or later.
What versions of PHP_CodeSniffer are affected by GHSA-hmqg-cxww-wqhq?
PHP_CodeSniffer versions before v3.13.6 and v4.0.2 are affected by GHSA-hmqg-cxww-wqhq.
What type of vulnerability is GHSA-hmqg-cxww-wqhq?
GHSA-hmqg-cxww-wqhq is categorized as a command injection vulnerability.
Where can GHSA-hmqg-cxww-wqhq be exploited?
GHSA-hmqg-cxww-wqhq can be exploited when running PHP_CodeSniffer over untrusted files, such as in a CI pipeline that scans pull requests.