Skip to content

Commit b451c89

Browse files
committed
Security/Twig: 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.
1 parent 714bc00 commit b451c89

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

WordPressVIPMinimum/Sniffs/Security/TwigSniff.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace WordPressVIPMinimum\Sniffs\Security;
1010

11+
use PHP_CodeSniffer\Util\Tokens;
1112
use WordPressVIPMinimum\Sniffs\Sniff;
1213

1314
/**
@@ -28,11 +29,7 @@ class TwigSniff extends Sniff {
2829
* @return array<int|string>
2930
*/
3031
public function register() {
31-
return [
32-
T_CONSTANT_ENCAPSED_STRING,
33-
T_INLINE_HTML,
34-
T_HEREDOC,
35-
];
32+
return Tokens::$textStringTokens;
3633
}
3734

3835
/**

WordPressVIPMinimum/Tests/Security/TwigUnitTest.inc

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,52 @@
99
{% autoescape %}
1010
{{ safe_value|raw }}
1111
{% endautoescape %}
12-
</script>
12+
</script>
13+
14+
<?php
15+
16+
echo '<script>
17+
{% autoescape false %}
18+
Everything will be outputted as is in this block
19+
{% endautoescape %}
20+
21+
{% autoescape %}
22+
{{ safe_value|raw }}
23+
{% endautoescape %}
24+
</script>';
25+
26+
echo "<script>
27+
{% autoescape false %}
28+
Everything will be $outputted as is in this block
29+
{% endautoescape %}
30+
31+
{% autoescape %}
32+
{{ safe_value|raw }}
33+
{% endautoescape %}
34+
</script>
35+
";
36+
37+
echo <<<'EOD'
38+
<script>
39+
{% autoescape false %}
40+
Everything will be outputted as is in this block
41+
{% endautoescape %}
42+
43+
{% autoescape %}
44+
{{ safe_value|raw }}
45+
{% endautoescape %}
46+
</script>
47+
EOD;
48+
49+
echo <<<EOD
50+
<script>
51+
{% autoescape false %}
52+
Everything will be $outputted as is in this block
53+
{% endautoescape %}
54+
EOD;
55+
echo <<<"EOD"
56+
{% autoescape %}
57+
{{ safe_value|raw }}
58+
{% endautoescape %}
59+
</script>
60+
EOD;

WordPressVIPMinimum/Tests/Security/TwigUnitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public function getWarningList() {
3434
return [
3535
5 => 1,
3636
10 => 1,
37+
17 => 1,
38+
22 => 1,
39+
27 => 1,
40+
32 => 1,
41+
39 => 1,
42+
44 => 1,
43+
51 => 1,
44+
57 => 1,
3745
];
3846
}
3947
}

0 commit comments

Comments
 (0)