Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP - Basic XSS not matching #1781

Closed
erwanlr opened this issue Oct 5, 2020 · 8 comments
Closed

PHP - Basic XSS not matching #1781

erwanlr opened this issue Oct 5, 2020 · 8 comments
Labels

Comments

@erwanlr
Copy link

erwanlr commented Oct 5, 2020

Describe the bug
I've been trying to write a pattern to catch a basic XSS, but it's always reported as Pattern could not be parsed as a PHP semgrep pattern

To Reproduce
https://semgrep.dev/s/1Ld5/

Expected behavior
I was expecting to have at least a match for the pattern echo $X

@Sjord
Copy link
Contributor

Sjord commented Oct 5, 2020

Try providing a complete statement by closing the pattern with a semicolon:

- pattern: echo $X;

@erwanlr
Copy link
Author

erwanlr commented Oct 5, 2020

@Sjord already tried that, does not work :/

@aryx aryx added the lang:php label Oct 5, 2020
@aryx
Copy link
Collaborator

aryx commented Oct 5, 2020

This works: https://semgrep.dev/s/Nx3A/

@aryx
Copy link
Collaborator

aryx commented Oct 5, 2020

Or this: https://semgrep.dev/s/kWye/

In semgrep you usually can't write partial construct, and echo in PHP is at the statement level, not expression level, so it has to finish with a ';'. Not sure why there was an antislash before the $_GET in your example, but yet it does not work.

@aryx aryx closed this as completed Oct 5, 2020
@rezen
Copy link

rezen commented Oct 7, 2020

@erwanlr a better example is https://semgrep.dev/s/KdzY - I also have a couple other rules here https://gist.github.com/rezen/9908fb3a0cbe1a38ffd15cbc8f43b6f0

@aryx where do community rulesets live? We could contribute some php rules - is https://github.com/returntocorp/semgrep-rules the place?

@aryx
Copy link
Collaborator

aryx commented Oct 7, 2020

Yes! We would love you to contribute rules in semgrep-rules.
@minusworld is managing this repo.

@erwanlr
Copy link
Author

erwanlr commented Oct 7, 2020

Thank you @rezen for the examples :)

There is still a bug (false positive), taking https://semgrep.dev/s/KdzY rules, echo $settings['something']; and echo CONSTANT['a']; will match but they shouldn't. It seems like $_GET[$KEY] is taken as $Y[$KEY] (hence why I tried to escape the first $ in my example above btw).

@aryx
Copy link
Collaborator

aryx commented Oct 7, 2020

You're right @erwanlr , I've created a separated issue for this bug just now: #1790

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

No branches or pull requests

4 participants