Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

CSRF shouldn't throw PHP errors when it receives non-string input #212

Merged
merged 2 commits into from
Feb 1, 2018

Conversation

Saeven
Copy link
Contributor

@Saeven Saeven commented Jan 23, 2018

The CSRF is a bit naive, assuming that it is receiving a string, and not an array. Most penetration tests start with malformed input, and arrays cause this validator to throw an Array to string conversion error.

Reproducing the problem is simple. Craft a form that includes a CSRF Filter, and modify your post to send CSRF as an array. e.g.,

POST /login HTTP/1.1 Content-Length: 142 Content-Type: application/x-www-form-urlencoded Referer: http://foo.com Cookie: PHPSESSID=s3r0icn96iqstvsrpkae3n2sta; lastRoute=register; locale=en_US; lastPageVisited=http://foo.com/login; __cfduid=d815a2363ab50c616e80627e0ca5834a81516720789 Host: foo.com
Connection: Keep-alive Accept-Encoding: gzip,deflate User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko Accept: */* axis=1&csrf[]=576ae4642376a2904866a504f395c75ab04205df5b1df8e0bbd999f6e6746c73&email=sample%40email.tst&password=g00dPa%24%24w0rD&remember=on

The CSRF filter should report a validation failure when an array is pushed in, and not crap out.

The CSRF is a bit naive, assuming that it is receiving a string, and not an array.  Most penetration tests start with malformed input, and arrays cause this validator to throw an Array to string conversion error.
@Saeven Saeven changed the title Update Csrf.php CSRF shouldn't throw PHP errors when it receives non-string input Jan 23, 2018
@Ocramius
Copy link
Member

Ocramius commented Jan 23, 2018 via email

@Saeven
Copy link
Contributor Author

Saeven commented Jan 23, 2018

Yep sorry, forgot to check it in. Done.

@Saeven
Copy link
Contributor Author

Saeven commented Jan 23, 2018

Hm, some tests in this branch (untouched) were failing already. Need fixing? Timezone tests.

@weierophinney weierophinney merged commit 9e13e74 into zendframework:master Feb 1, 2018
weierophinney added a commit that referenced this pull request Feb 1, 2018
CSRF shouldn't throw PHP errors when it receives non-string input
weierophinney added a commit that referenced this pull request Feb 1, 2018
weierophinney added a commit that referenced this pull request Feb 1, 2018
weierophinney added a commit that referenced this pull request Feb 1, 2018
@weierophinney
Copy link
Member

Thanks, @Saeven!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants