Skip to content

Conversation

wenz
Copy link
Contributor

@wenz wenz commented Sep 16, 2016

fixes #15048

@@ -2,7 +2,7 @@

sleep( 2 );
// no term passed - just exit early with no response
if (empty($_GET['term'])) exit ;
if (!isset($_GET["term"]) || empty($_GET['term'])) exit ;
Copy link
Member

Choose a reason for hiding this comment

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

This isset() is duplicative of the empty() check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed. Fixed.

remove redundant isset() check
Copy link
Contributor Author

@wenz wenz left a comment

Choose a reason for hiding this comment

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

removed the isset() check. Thanks for the pointer!

@scottgonzalez
Copy link
Member

This is too restrictive; it would reject many valid callback function names. Properly validating the callback name is too complex and there's no actual attack vector to worry about here.

@wenz
Copy link
Contributor Author

wenz commented Sep 21, 2016

I respectfully disagree.

  1. in the context of the demo, the filtering works fine, since it alows jQuery's default callback name consisting of jQuery, many digits, and one underscore. In addition, which valid callback function name is rejected by the regex? We might consider making $ and . valid characters, but what else is missing?
  2. PoC: put the (unpatched) file on a web server and load http://server/path/to/search.php?callback=<script>alert(1)</script>&term=X in a browser without built-in XSS protection (e.g. Firefox). The JavaScript code is executed in the security context of the target server, a classic XSS vector.

@scottgonzalez
Copy link
Member

In addition, which valid callback function name is rejected by the regex? We might consider making $ and . valid characters, but what else is missing?

Tons and tons of unicode characters are missing.

  1. PoC: put the (unpatched) file on a web server and load http://server/path/to/search.php?callback=&term=X in a browser without built-in XSS protection (e.g. Firefox). The JavaScript code is executed in the security context of the target server, a classic XSS vector.

The JavaScript code being an array, which does nothing. How is that a classic XSS vector?

@wenz
Copy link
Contributor Author

wenz commented Sep 21, 2016

GitHub ate the script tag in my URL. Try this:
http://server/path/to/search.php?callback=[script]alert(1)[/script]&term=X
but replace the square brackets with angle brackets.

@scottgonzalez
Copy link
Member

So this is about linking directly to search.php and injecting HTML, not about injecting JS in the JSONP request. Simply passing the callback through htmlspecialchars() would prevent someone from pretending to load a real page and won't break any valid callback names.

@wenz
Copy link
Contributor Author

wenz commented Sep 22, 2016

htmlspecialchars() would also work, however I personally prefer the validation approach over escaping here, since a callback name with (for instance) angle brackets should lead to nothing being returned.

The proposed fix works for the sample code. If someone is changing the example, e.g. by using a callback name with unicode characters, it's probably their responsibility to adapt the PHP script, as well. If you wish, I could amend the PR to use htmlspecialchars() despite my reservations.

Anyway, this must be fixed asap, since the same file is also residing on the jqueryui.com domain.

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

Successfully merging this pull request may close these issues.

3 participants