php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62013 Htmlentities doesn't convert the characters (,),: to a named entity
Submitted: 2012-05-13 01:01 UTC Modified: 2012-05-13 01:53 UTC
From: c dot noesterer at gmail dot com Assigned:
Status: Not a bug Package: Filter related
PHP Version: 5.4.3 OS: Linux 3.3.4-1-ARCH
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: c dot noesterer at gmail dot com
New email:
PHP Version: OS:

 

 [2012-05-13 01:01 UTC] c dot noesterer at gmail dot com
Description:
------------
Htmlentities doesn't convert the characters (,),: to a named entity.

Therefore a XSS-attack works for the script attached:
?test=javascript:alert(1);

Test script:
---------------
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
echo '<a href='.htmlentities($_GET["test"]).'>test</a>';
?>
</body>
</html>


Expected result:
----------------
<a href=javascript&colon;alert&lpar;1&rpar;>test</a>

Actual result:
--------------
<a href=javascript:alert(1);>test</a>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-13 01:53 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-05-13 01:53 UTC] rasmus@php.net
You are using the wrong function. htmlentities() for encoding entities special to 
HTML. Inside an href tag you don't have HTML, you have a URL so you need to use 
urlencode().
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Dec 05 17:03:50 2022 UTC