Skip to content

IncludingFile: Add custom keywords to detect to reduce false positives#626

Closed
rebeccahum wants to merge 2 commits into
developfrom
rebecca/fix_407
Closed

IncludingFile: Add custom keywords to detect to reduce false positives#626
rebeccahum wants to merge 2 commits into
developfrom
rebecca/fix_407

Conversation

@rebeccahum

Copy link
Copy Markdown
Contributor

Fixes #407.

Takes into account for URLs and $restrictedConstants with keywords from $customPaths.

@rebeccahum rebeccahum requested a review from a team as a code owner February 24, 2021 16:16

@jrfnl jrfnl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Rebecca,

I've been looking at this change and notice I find it difficult to review it as there is so much more which needs improving in this sniff, that it is hard to focus on this specific change.

This might actually be a good sniff to take the time to dissect in detail in a live coding call and talk through every code inefficiency and assumption in the code which should be fixed.

For now, specifically for this PR, let's start with some questions (left in-line)...

return;
}

if ( $this->tokens[ $nextToken ]['code'] === T_CONSTANT_ENCAPSED_STRING && filter_var( str_replace( [ '"', "'" ], '', $this->tokens[ $nextToken ]['content'] ), FILTER_VALIDATE_URL ) ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move this check up ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it up so that it doesn't bail before checking for an external URL with a keyword from $customPaths in it. e.g.:

include( "http://path.com/bad_file.php" );

Comment thread WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php Outdated
Comment thread WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php Outdated
Comment thread WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc Outdated
@rebeccahum rebeccahum requested a review from jrfnl March 12, 2021 21:40
@rebeccahum

Copy link
Copy Markdown
Contributor Author

Closing for now as per our discussion on making this an atomic commit for the next release and then doing more re-factoring for 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimize false positives on WordPressVIPMinimum.Files.IncludingFile.IncludingFile

2 participants