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

Anchoring in Regular Expression Checks #21

Closed
knaveofdiamonds opened this issue Dec 9, 2011 · 3 comments
Closed

Anchoring in Regular Expression Checks #21

knaveofdiamonds opened this issue Dec 9, 2011 · 3 comments

Comments

@knaveofdiamonds
Copy link

Not entirely sure if this is a bug/incomplete feature or not. In the Regular Expression checks, you're looking for \A and \Z to check that the validation is anchored correctly. Is it not equally valid to use '^' and '$' (which is what I'm doing, resulting in what might be false positives if my understanding is right)?

Happy to provide a patch to fix this if '^' and '$' should be allowed as well.

@presidentbeef
Copy link
Owner

Hi Roland, thanks for the feedback!

However, these are not false positives. Using ^ and $ is not sufficient, as they will match newlines. Once a newline is encountered, the pattern is matched, allowing an attacker to insert whatever they wish after that (or before, if ^ is used).

The Rails Security Guide has a good explanation of this issue.

@joealba
Copy link

joealba commented Dec 9, 2011

In Ruby, the '$' serves as an end-of-line anchor, not end-of-string. Dan Kubb wrote a gist which describes this issue pretty well:

https://gist.github.com/1444431

@knaveofdiamonds
Copy link
Author

Thanks for clearing that up.

Repository owner locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants