Skip to content

Commit

Permalink
Security/Mustache: prevent false positives on block editor templates
Browse files Browse the repository at this point in the history
As reported in 541#issuecomment-1692323177.

This commit fixes the issue + adds a test to safeguard the fix.
  • Loading branch information
jrfnl committed Aug 26, 2023
1 parent 92a8c82 commit 22e31f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WordPressVIPMinimum/Sniffs/Security/MustacheSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function register() {
*/
public function process_token( $stackPtr ) {

if ( strpos( $this->tokens[ $stackPtr ]['content'], '{{{' ) !== false || strpos( $this->tokens[ $stackPtr ]['content'], '}}}' ) !== false ) {
if ( strpos( $this->tokens[ $stackPtr ]['content'], '{{{' ) !== false && strpos( $this->tokens[ $stackPtr ]['content'], '}}}' ) !== false ) {
// Mustache unescaped output notation.
$message = 'Found Mustache unescaped output notation: "{{{}}}".';
$this->phpcsFile->addWarning( $message, $stackPtr, 'OutputNotation' );
Expand Down
5 changes: 4 additions & 1 deletion WordPressVIPMinimum/Tests/Security/MustacheUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ echo '<a href="{{href}}">{{&data}}</div></a>'; // NOK: data.

return new Handlebars.SafeString(result); // NOK: SafeString.
});
</script>
</script>

// Issue 541#issuecomment-1692323177: don't flag GB syntax.
<div class="wp-block-group"><!-- wp:heading {"textAlign":"center","style":{"spacing":{"margin":{"top":"0","right":"0","bottom":"var:preset|spacing|medium","left":"0"}}}} --><!-- OK. -->

0 comments on commit 22e31f7

Please sign in to comment.