2006-08-12 01:12:35 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-17 01:05:35 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
2007-08-01 14:55:09 +00:00
|
|
|
require_once 'HTMLPurifier/URIParser.php';
|
2006-08-12 01:12:35 +00:00
|
|
|
require_once 'HTMLPurifier/URIScheme.php';
|
|
|
|
require_once 'HTMLPurifier/URISchemeRegistry.php';
|
2007-02-14 20:38:51 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/URI/Host.php';
|
2006-11-07 17:15:28 +00:00
|
|
|
require_once 'HTMLPurifier/PercentEncoder.php';
|
2007-08-06 06:22:23 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/URI/Email.php';
|
2006-08-12 01:12:35 +00:00
|
|
|
|
2007-08-02 21:47:24 +00:00
|
|
|
// special case filtering directives
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2006-11-12 03:35:41 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2007-08-02 21:47:24 +00:00
|
|
|
'URI', 'Munge', null, 'string/null', '
|
|
|
|
<p>
|
|
|
|
Munges all browsable (usually http, https and ftp)
|
|
|
|
absolute URI\'s into another URI, usually a URI redirection service.
|
|
|
|
This directive accepts a URI, formatted with a <code>%s</code> where
|
|
|
|
the url-encoded original URI should be inserted (sample:
|
|
|
|
<code>http://www.google.com/url?q=%s</code>).
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Uses for this directive:
|
|
|
|
</p>
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
Prevent PageRank leaks, while being fairly transparent
|
|
|
|
to users (you may also want to add some client side JavaScript to
|
|
|
|
override the text in the statusbar). <strong>Notice</strong>:
|
|
|
|
Many security experts believe that this form of protection does not deter spam-bots.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Redirect users to a splash page telling them they are leaving your
|
|
|
|
website. While this is poor usability practice, it is often mandated
|
|
|
|
in corporate environments.
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p>
|
|
|
|
This directive has been available since 1.3.0.
|
|
|
|
</p>
|
|
|
|
');
|
2006-11-12 03:35:41 +00:00
|
|
|
|
2007-08-02 21:47:24 +00:00
|
|
|
// disabling directives
|
2006-11-23 23:59:20 +00:00
|
|
|
|
2006-11-24 00:29:16 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2007-08-02 21:47:24 +00:00
|
|
|
'URI', 'Disable', false, 'bool', '
|
|
|
|
<p>
|
|
|
|
Disables all URIs in all forms. Not sure why you\'d want to do that
|
|
|
|
(after all, the Internet\'s founded on the notion of a hyperlink).
|
|
|
|
This directive has been available since 1.3.0.
|
|
|
|
</p>
|
|
|
|
');
|
|
|
|
HTMLPurifier_ConfigSchema::defineAlias('Attr', 'DisableURI', 'URI', 'Disable');
|
2006-11-24 00:29:16 +00:00
|
|
|
|
2007-02-14 01:57:06 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2007-08-02 21:47:24 +00:00
|
|
|
'URI', 'DisableResources', false, 'bool', '
|
|
|
|
<p>
|
|
|
|
Disables embedding resources, essentially meaning no pictures. You can
|
|
|
|
still link to them though. See %URI.DisableExternalResources for why
|
|
|
|
this might be a good idea. This directive has been available since 1.3.0.
|
|
|
|
</p>
|
|
|
|
');
|
2007-02-14 01:57:06 +00:00
|
|
|
|
2006-08-20 21:47:15 +00:00
|
|
|
/**
|
|
|
|
* Validates a URI as defined by RFC 3986.
|
|
|
|
* @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme
|
|
|
|
*/
|
2006-08-12 01:12:35 +00:00
|
|
|
class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
|
|
|
{
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
var $parser, $percentEncoder;
|
|
|
|
var $embedsResource;
|
2006-08-17 01:05:35 +00:00
|
|
|
|
2006-11-17 23:09:10 +00:00
|
|
|
/**
|
2006-11-23 23:59:20 +00:00
|
|
|
* @param $embeds_resource_resource Does the URI here result in an extra HTTP request?
|
2006-11-17 23:09:10 +00:00
|
|
|
*/
|
2006-11-23 23:59:20 +00:00
|
|
|
function HTMLPurifier_AttrDef_URI($embeds_resource = false) {
|
2007-08-01 14:55:09 +00:00
|
|
|
$this->parser = new HTMLPurifier_URIParser();
|
2007-08-01 18:34:46 +00:00
|
|
|
$this->percentEncoder = new HTMLPurifier_PercentEncoder();
|
|
|
|
$this->embedsResource = (bool) $embeds_resource;
|
2006-08-17 01:05:35 +00:00
|
|
|
}
|
|
|
|
|
2006-08-12 16:04:40 +00:00
|
|
|
function validate($uri, $config, &$context) {
|
2006-08-12 01:12:35 +00:00
|
|
|
|
2007-02-14 01:57:06 +00:00
|
|
|
if ($config->get('URI', 'Disable')) return false;
|
|
|
|
|
2007-08-01 14:55:09 +00:00
|
|
|
// initial operations
|
2006-08-12 01:12:35 +00:00
|
|
|
$uri = $this->parseCDATA($uri);
|
2007-08-01 18:34:46 +00:00
|
|
|
$uri = $this->percentEncoder->normalize($uri);
|
2006-11-07 17:15:28 +00:00
|
|
|
|
2007-08-01 14:55:09 +00:00
|
|
|
// parse the URI
|
2007-08-01 18:34:46 +00:00
|
|
|
$uri = $this->parser->parse($uri);
|
|
|
|
if ($uri === false) return false;
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
// add embedded flag to context for validators
|
|
|
|
$context->register('EmbeddedURI', $this->embedsResource);
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
$ok = false;
|
|
|
|
do {
|
|
|
|
|
|
|
|
// generic validation
|
|
|
|
$result = $uri->validate($config, $context);
|
|
|
|
if (!$result) break;
|
|
|
|
|
|
|
|
// chained validation
|
|
|
|
$uri_def =& $config->getDefinition('URI');
|
|
|
|
$result = $uri_def->filter($uri, $config, $context);
|
|
|
|
if (!$result) break;
|
|
|
|
|
|
|
|
// scheme-specific validation
|
|
|
|
$scheme_obj = $uri->getSchemeObj($config, $context);
|
|
|
|
if (!$scheme_obj) break;
|
|
|
|
if ($this->embedsResource && !$scheme_obj->browsable) break;
|
|
|
|
$result = $scheme_obj->validate($uri, $config, $context);
|
|
|
|
if (!$result) break;
|
|
|
|
|
|
|
|
// survived gauntlet
|
|
|
|
$ok = true;
|
|
|
|
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
$context->destroy('EmbeddedURI');
|
|
|
|
if (!$ok) return false;
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2007-08-02 01:41:37 +00:00
|
|
|
// munge scheme off if necessary (this must be last)
|
|
|
|
if (!is_null($uri->scheme) && is_null($uri->host)) {
|
2007-08-02 21:47:24 +00:00
|
|
|
if ($uri_def->defaultScheme == $uri->scheme) {
|
2007-08-02 01:41:37 +00:00
|
|
|
$uri->scheme = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
// back to string
|
|
|
|
$result = $uri->toString();
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2007-08-02 01:41:37 +00:00
|
|
|
// munge entire URI if necessary
|
2007-08-01 18:34:46 +00:00
|
|
|
if (
|
|
|
|
!is_null($uri->host) && // indicator for authority
|
|
|
|
!empty($scheme_obj->browsable) &&
|
|
|
|
!is_null($munge = $config->get('URI', 'Munge'))
|
|
|
|
) {
|
|
|
|
$result = str_replace('%s', rawurlencode($result), $munge);
|
2006-11-24 00:29:16 +00:00
|
|
|
}
|
|
|
|
|
2006-08-12 03:35:05 +00:00
|
|
|
return $result;
|
|
|
|
|
2006-08-12 01:12:35 +00:00
|
|
|
}
|
2006-08-12 03:35:05 +00:00
|
|
|
|
2006-08-12 01:12:35 +00:00
|
|
|
}
|
|
|
|
|
2007-06-27 13:58:32 +00:00
|
|
|
|