1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Fix an XSS issue with certain high-priority remarkup rules embedded inside lower-priority link rules

Summary:
See <https://hackerone.com/reports/758002>. The link rules don't test that their parameters are flat text before using them in unsafe contexts.

Since almost all rules are lower-priority than these link rules, this behavior isn't obvious. However, two rules have broadly higher priority (monospaced text, and one variation of link rules has higher priority than the other), and the latter can be used to perform an XSS attack with input in the general form `()[ [[ ... | ... ]] ]` so that the inner link rule is evaluated first, then the outer link rule uses non-flat text in an unsafe way.

Test Plan:
Tested examples in HackerOne report. A simple example of broken (but not unsafe) behavior is:

```
[[ `x` | `y` ]]
```

Differential Revision: https://secure.phabricator.com/D20937
This commit is contained in:
epriestley 2019-12-13 10:31:44 -08:00
parent 4cd333b33f
commit 54bcbdaba9
2 changed files with 24 additions and 6 deletions

View file

@ -16,8 +16,23 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
}
public function markupDocumentLink(array $matches) {
$name = trim(idx($matches, 2, ''));
if (empty($matches[2])) {
$name = null;
}
$path = trim($matches[1]);
if (!$this->isFlatText($name)) {
return $matches[0];
}
if (!$this->isFlatText($path)) {
return $matches[0];
}
// If the link contains an anchor, separate that off first.
$parts = explode('#', trim($matches[1]), 2);
$parts = explode('#', $path, 2);
if (count($parts) == 2) {
$link = $parts[0];
$anchor = $parts[1];
@ -48,11 +63,6 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
}
}
$name = trim(idx($matches, 2, ''));
if (empty($matches[2])) {
$name = null;
}
// Link is now used for slug detection, so append a slash if one
// is needed.
$link = rtrim($link, '/').'/';

View file

@ -136,6 +136,14 @@ final class PhutilRemarkupDocumentLinkRule extends PhutilRemarkupRule {
$uri = trim($matches[1]);
$name = trim(idx($matches, 2));
if (!$this->isFlatText($uri)) {
return $matches[0];
}
if (!$this->isFlatText($name)) {
return $matches[0];
}
// If whatever is being linked to begins with "/" or "#", or has "://",
// or is "mailto:" or "tel:", treat it as a URI instead of a wiki page.
$is_uri = preg_match('@(^/)|(://)|(^#)|(^(?:mailto|tel):)@', $uri);