File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace PHPCS_SecurityAudit \Security \Sniffs \Misc ;
3+
4+ use PHP_CodeSniffer \Sniffs \Sniff ;
5+ use PHP_CodeSniffer \Files \File ;
6+
7+
8+ class TypeJuggleSniff implements Sniff {
9+
10+ /**
11+ * Returns the token types that this sniff is interested in.
12+ *
13+ * @return array(int)
14+ */
15+ public function register () {
16+ return array (T_IS_EQUAL , T_IS_NOT_EQUAL );
17+ }
18+
19+ /**
20+ * Processes the tokens that this sniff is interested in.
21+ *
22+ * @param File $phpcsFile The file where the token was found.
23+ * @param int $stackPtr The position in the stack where
24+ * the token was found.
25+ *
26+ * @return void
27+ */
28+ public function process (File $ phpcsFile , $ stackPtr ) {
29+ $ tokens = $ phpcsFile ->getTokens ();
30+ if (\PHP_CodeSniffer \Config::getConfigData ('ParanoiaMode ' )) {
31+ $ warning = 'You are using the comparison operator " ' . $ tokens [$ stackPtr ]['content ' ] .'" that converts type and may cause unintended results. ' ;
32+ $ phpcsFile ->addWarning ($ warning , $ stackPtr , 'TypeJuggle ' );
33+ }
34+ }
35+
36+ }
37+
38+ ?>
Original file line number Diff line number Diff line change 4747<!-- Misc -->
4848<rule ref =" Security.Misc.BadCorsHeader" />
4949<rule ref =" Security.Misc.IncludeMismatch" />
50+ <rule ref =" Security.Misc.TypeJuggle" />
5051
5152</ruleset >
5253
Original file line number Diff line number Diff line change 1111 preg_replace ($ _GET ['b ' ], $ _GET ['a ' ], $ _GET ['c ' ]);
1212 preg_replace ($ b , $ _GET ['a ' ], 'aaaaaa ' );
1313 preg_replace ("aaa " , $ _GET ['a ' ], 'ababaaa ' );
14-
14+
1515
1616 // BadFunctions
1717 md5 ();
4444 $ a ->withHeader ('Access-Control-Allow-Origin ' , '* ' );
4545 include ('abc.xyz ' );
4646 require_once EXTENSION_PATH . '/path/to ' . $ name . '.jkl ' ;
47+ 0 == '0 cats ' ;
4748
4849 // Easy user input
4950 $ _GET ['a ' ] = 'xss ' ;
You can’t perform that action at this time.
0 commit comments