mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 13:47:24 +02:00
Dramatically rewrite null host URI handling.
Basically, browsers don't parse what should be valid URIs correctly, so we have to go through some backbends to accomodate them. Specifically, for browseable URIs, the following URIs have unintended behavior: - ///example.com - http:/example.com - http:///example.com Furthermore, if the path begins with //, modifying these URLs must be done with care, as if you remove the host-name component, the parse tree changes. I've modified the engine to follow correct URI semantics as much as possible while outputting browser compatible code, and invalidate the URI in cases where we can't deal. There has been a refactoring of URIScheme so that this important check is always performed, introducing a new member variable allow_empty_host which is true on data, file, mailto and news schemes. This also fixes bypass bugs on URI.Munge. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
@@ -74,6 +74,15 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
|
||||
$this->assertDef('mailto:this-looks-like-a-path@example.com');
|
||||
}
|
||||
|
||||
function testResolveNullSchemeAmbiguity() {
|
||||
$this->assertDef('///foo', '/foo');
|
||||
}
|
||||
|
||||
function testResolveNullSchemeDoubleAmbiguity() {
|
||||
$this->config->set('URI.Host', 'example.com');
|
||||
$this->assertDef('////foo', '//example.com//foo');
|
||||
}
|
||||
|
||||
function testURIDefinitionValidation() {
|
||||
$parser = new HTMLPurifier_URIParser();
|
||||
$uri = $parser->parse('http://example.com');
|
||||
|
52
tests/HTMLPurifier/HTMLT/munge.htmlt
Normal file
52
tests/HTMLPurifier/HTMLT/munge.htmlt
Normal file
@@ -0,0 +1,52 @@
|
||||
--INI--
|
||||
URI.Munge = "/r/%s"
|
||||
URI.AllowedSchemes = http,ftp,file
|
||||
--HTML--
|
||||
<a href="google.com">foo</a>
|
||||
<a href="/google.com">foo</a>
|
||||
<a href="//google.com">foo</a>
|
||||
<a href="///google.com">foo</a>
|
||||
<a href="////google.com">foo</a>
|
||||
|
||||
<a href="http:google.com">foo</a>
|
||||
<a href="http:/google.com">foo</a>
|
||||
<a href="http://google.com">foo</a>
|
||||
<a href="http:///google.com">foo</a>
|
||||
<a href="http:////google.com">foo</a>
|
||||
|
||||
<a href="ftp:google.com">foo</a>
|
||||
<a href="ftp:/google.com">foo</a>
|
||||
<a href="ftp://google.com">foo</a>
|
||||
<a href="ftp:///google.com">foo</a>
|
||||
<a href="ftp:////google.com">foo</a>
|
||||
|
||||
<a href="file:google.com">foo</a>
|
||||
<a href="file:/google.com">foo</a>
|
||||
<a href="file://google.com">foo</a>
|
||||
<a href="file:///google.com">foo</a>
|
||||
<a href="file:////google.com">foo</a>
|
||||
--EXPECT--
|
||||
<a href="google.com">foo</a>
|
||||
<a href="/google.com">foo</a>
|
||||
<a href="/r/%2F%2Fgoogle.com">foo</a>
|
||||
<a href="/google.com">foo</a>
|
||||
<a>foo</a>
|
||||
|
||||
<a href="google.com">foo</a>
|
||||
<a href="/google.com">foo</a>
|
||||
<a href="/r/http%3A%2F%2Fgoogle.com">foo</a>
|
||||
<a href="/google.com">foo</a>
|
||||
<a>foo</a>
|
||||
|
||||
<a>foo</a>
|
||||
<a>foo</a>
|
||||
<a href="/r/ftp%3A%2F%2Fgoogle.com">foo</a>
|
||||
<a>foo</a>
|
||||
<a>foo</a>
|
||||
|
||||
<a href="file:google.com">foo</a>
|
||||
<a href="file:/google.com">foo</a>
|
||||
<a href="file://google.com">foo</a>
|
||||
<a href="file:///google.com">foo</a>
|
||||
<a href="file:////google.com">foo</a>
|
||||
--# vim: et sw=4 sts=4
|
@@ -172,6 +172,17 @@ class HTMLPurifier_URISchemeTest extends HTMLPurifier_URIHarness
|
||||
);
|
||||
}
|
||||
|
||||
function test_file_local() {
|
||||
$this->assertValidation(
|
||||
'file:///foo/bar?baz#frag',
|
||||
'file:///foo/bar#frag'
|
||||
);
|
||||
}
|
||||
|
||||
function test_ftp_empty_host() {
|
||||
$this->assertValidation('ftp:///example.com', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
@@ -157,7 +157,7 @@ class HTMLPurifier_URITest extends HTMLPurifier_URIHarness
|
||||
}
|
||||
|
||||
function test_validate_invalidHostThatLooksLikeIPv6() {
|
||||
$this->assertValidation('http://[2001:0db8:85z3:08d3:1319:8a2e:0370:7334]', 'http:');
|
||||
$this->assertValidation('http://[2001:0db8:85z3:08d3:1319:8a2e:0370:7334]', '');
|
||||
}
|
||||
|
||||
function test_validate_removeRedundantScheme() {
|
||||
|
Reference in New Issue
Block a user