|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-02-15 05:21 UTC] pecoes at gmail dot com
Description: ------------ Look at the code and its result. How is that validation? Reproduce code: --------------- $url = 'http://example.org/"><script>alert(\'oops\');</script'; echo '<a href="', filter_var($url, FILTER_VALIDATE_URL), '">test</a>'; Expected result: ---------------- <a href="">test</a> Actual result: -------------- <a href="http://example.org/"><script>alert('oops');</script">test</a> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 07:00:01 2025 UTC |
What you are after is a filter for the html-context. There is nothing wrong with your URL. You only have an issue with it if you use it in an HTML context. It is your target context you should be filtering for. The URL sanitizer is very explicitly documented as: Remove all characters except letters, digits and $- _.+!*'(),{}|\\^~[]`<>#%";/?:@&=. Have a look through: http://php.net/manual/en/filter.filters.sanitize.php What you are looking for is FILTER_SANITIZE_SPECIAL_CHARS