Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions lib/Service/HtmlPurify/TransformHTMLLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,18 @@
use HTMLPurifier_AttrTransform;
use HTMLPurifier_Config;
use HTMLPurifier_Context;
use HTMLPurifier_URIParser;
use OCP\IURLGenerator;

/**
* Adds target="_blank" to all outbound links.
*/
class TransformHTMLLinks extends HTMLPurifier_AttrTransform {

/**
* @type HTMLPurifier_URIParser
*/
private $parser;

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
$this->parser = new HTMLPurifier_URIParser();
}

/**
Expand All @@ -59,7 +52,7 @@ public function transform($attr, $config, $context) {
}

$attr['target'] = '_blank';
$attr['rel'] = 'noopener';
$attr['rel'] = 'external noopener noreferrer';

// Open mailto: links in Mail
if (stripos($attr['href'], 'mailto:') === 0) {
Expand Down
25 changes: 9 additions & 16 deletions lib/Service/HtmlPurify/TransformURLScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,16 @@ private function filterHttpFtp(&$uri, $context) {
// If element is of type "href" it is most likely a link that should get redirected
// otherwise it's an element that we send through our proxy
if ($element === 'href') {
$uri = new \HTMLPurifier_URI(
$this->request->getServerProtocol(),
null,
$this->request->getServerHost(),
null,
$this->urlGenerator->linkToRoute('mail.proxy.redirect'),
'src=' . $originalURL,
null
);
return $uri;
} else {
$uri = new \HTMLPurifier_URI(
$this->request->getServerProtocol(), null, $this->request->getServerHost(), null,
$this->urlGenerator->linkToRoute('mail.proxy.proxy'),
'src=' . $originalURL . '&requesttoken=' . \OC::$server->getSession()->get('requesttoken'),
null);
return $uri;
}

return new \HTMLPurifier_URI(
$this->request->getServerProtocol(),
null, $this->request->getServerHost(),
null,
$this->urlGenerator->linkToRoute('mail.proxy.proxy'),
'src=' . $originalURL . '&requesttoken=' . \OC::$server->getSession()->get('requesttoken'),
null
);
}
}