Skip to content

Security/Mustache: sniff improvements#842

Merged
GaryJones merged 4 commits intodevelopfrom
feature/security-mustache-sniff-improvements
Jul 17, 2025
Merged

Security/Mustache: sniff improvements#842
GaryJones merged 4 commits intodevelopfrom
feature/security-mustache-sniff-improvements

Conversation

@jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Jul 16, 2025

Security/Mustache: sniff for all text string tokens

As things were, double quoted strings with interpolation and PHP 5.3+ nowdocs were not examined.

Includes ensuring that all tokens which should be examined have tests associated with them.

Note: the T_STRING token in the registed() method looks out of place, but is probably included to support JS scanning, though there are no tests for JS files.
As support for scanning JS is being removed in PHPCS 4.0, verifying (and probably fixing) JS support by adding tests is not worth spending time on.

Security/Mustache: improve tests

Make sure some tests contain more complex PHP interpolated expressions to ensure this doesn't lead to false positives.

Note: as I haven't been able to come up with valid code samples which would confuse the Mustache syntax with PHP interpolated expressions, I have not implemented the use of the TextStrings::stripEmbeds() method, though that could be considered for the future (would need double-checking that the method does not get confused over the Mustache syntaxes).

Security/Mustache: bug fix - potential false positives for delimiter change

The sniff didn't have enough guard code to safeguard that the test cases I've added in this commit would be handled correctly.

Fixed now.

Security/Mustache: prevent false positive on partial text

Includes test.

Closes #541

jrfnl added 2 commits July 17, 2025 00:58
As things were, double quoted strings with interpolation and PHP 5.3+ nowdocs were not examined.

Includes ensuring that all tokens which should be examined have tests associated with them.

Note: the `T_STRING` token looks out of place, but is probably included to support JS scanning, though there are no tests for JS files.
As support for scanning JS is being removed in PHPCS 4.0, verifying (and probably fixing) JS support by adding tests is not worth spending time on.
Make sure some tests contain more complex PHP interpolated expressions to ensure this doesn't lead to false positives.

Note: as I haven't been able to come up with valid code samples which would confuse the Mustache syntax with PHP interpolated expressions, I have not implemented the use of the `TextStrings::stripEmbeds()` method.
@jrfnl jrfnl added this to the 3.1.0 milestone Jul 16, 2025
@jrfnl jrfnl requested a review from a team as a code owner July 16, 2025 23:11
jrfnl added 2 commits July 17, 2025 02:50
…change

The sniff didn't have enough guard code to safeguard that the test cases I've added in this commit would be handled correctly.

Fixed now.
@jrfnl jrfnl force-pushed the feature/security-mustache-sniff-improvements branch from 794ab73 to 0aebe1f Compare July 17, 2025 00:50
@GaryJones GaryJones merged commit a83f273 into develop Jul 17, 2025
42 checks passed
@GaryJones GaryJones deleted the feature/security-mustache-sniff-improvements branch July 17, 2025 06:34
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.

Review the WordPressVIPMinimum.Security.Mustache sniff

2 participants