Commit 63ae7ddd authored by Helmut Hummel's avatar Helmut Hummel Committed by Oliver Hader
Browse files

[!!!][SECURITY] Fix link spoofing in prefixLocalAnchors

Specially crafted request could lead to anchors prefixed
with URLs to domains controlled by the attacker on the
domain root page (home page). No other pages are affected!

Fix this by prefixing the anchors with a canonical URL
to the current request. This could lead to the situation
that the prefix does not match the current REQUEST_URI
which leads to a page reload instead of just "jumping" to the page section.

Additionally this change assures that REQUEST_URI always starts
with a slash, which mitigates similar attack vectors when using
getIndpEnv('REQUEST_URI')

To mitigate the impact of this breaking change, the REQUEST_URI
is used for anchor prefix if a backend user is logged in,
to not disturb the preview functionality of the home page.

In case prefixLocalAnchors is used in the HTML parser configuration
with prefixLocalAnchors = 2, always the canonical URL is used as prefix.

This change does *not* fix, that arbitrary (non functional) GET parameters
will be included in the generated prefix URL. To fix this it is recommended
to use absRefPrefix instead of baseUrl and prefixLocalAnchors.

Resolves: #62723
Releases: 4.5, 6.2, master
Security-Commit: 16003fd71982a9da3fde04c7cc298425d8b539dc
Security-Bulletin: TYPO3-CORE-SA-2014-003
Change-Id: I120f7a0fa32e48644c88d54d65863a6ac96acf4c
Reviewed-on: http://review.typo3.org/35222


Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent 5c267d20
......@@ -4013,7 +4013,7 @@ final class t3lib_div {
$retVal = '/' . ltrim(self::getIndpEnv('SCRIPT_NAME'), '/') .
($_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '');
} else {
$retVal = $_SERVER['REQUEST_URI'];
$retVal = '/' . ltrim($_SERVER['REQUEST_URI'], '/');
}
// add a prefix if TYPO3 is behind a proxy: ext-domain.com => int-server.com/prefix
if (self::cmpIP($_SERVER['REMOTE_ADDR'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'])) {
......
......@@ -868,11 +868,14 @@ class t3lib_parsehtml {
}
if ($params['prefixLocalAnchors']) {
if (substr($tagAttrib[0][$attr], 0, 1) == '#') {
$prefix = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
$tagAttrib[0][$attr] = $prefix . $tagAttrib[0][$attr];
if ($params['prefixLocalAnchors'] == 2 && t3lib_div::isFirstPartOfStr($prefix, t3lib_div::getIndpEnv('TYPO3_SITE_URL'))) {
$tagAttrib[0][$attr] = substr($tagAttrib[0][$attr], strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL')));
if ($params['prefixLocalAnchors'] == 2) {
/** @var tslib_cObj $contentObjectRenderer */
$contentObjectRenderer = t3lib_div::makeInstance('tslib_cObj');
$prefix = $contentObjectRenderer->getUrlToCurrentLocation();
} else {
$prefix = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
}
$tagAttrib[0][$attr] = $prefix . $tagAttrib[0][$attr];
}
}
if ($params['prefixRelPathWith']) {
......
......@@ -6109,6 +6109,29 @@ class tslib_cObj {
return $out;
}
/**
* Returns the canonical URL to the current "location", which include the current page ID and type
* and optionally the query string
*
* @param bool $addQueryString Whether additional GET arguments in the query string should be included or not
* @return string
*/
public function getUrlToCurrentLocation($addQueryString = TRUE) {
$conf = array();
$conf['parameter'] = $GLOBALS['TSFE']->id . ',' . $GLOBALS['TSFE']->type;
if ($addQueryString) {
$conf['addQueryString'] = '1';
$linkVars = implode(',', array_keys(t3lib_div::explodeUrl2Array($GLOBALS['TSFE']->linkVars)));
$conf['addQueryString.'] = array(
'method' => 'GET',
'exclude' => 'id,type,cHash' . ($linkVars ? ',' . $linkVars : '')
);
$conf['useCacheHash'] = t3lib_div::_GET('cHash') ? '1' : '0';
}
return $this->typoLink_URL($conf);
}
/**
* Returns the URL of a "typolink" create from the input parameter string, url-parameters and target
*
......
......@@ -4404,7 +4404,14 @@ if (version == "n3") {
* @return void Works directly on $this->content
*/
function prefixLocalAnchorsWithScript() {
$scriptPath = $GLOBALS['TSFE']->absRefPrefix . substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL')));
if (!$this->beUserLogin) {
$scriptPath = $this->cObj->getUrlToCurrentLocation();
} else {
// To break less existing sites, we allow the REQUEST_URI to be used for the prefix
$scriptPath = t3lib_div::getIndpEnv('REQUEST_URI');
// Disable the cache so that these URI will not be the ones to be cached
$this->disableCache();
}
$originalContent = $this->content;
$this->content = preg_replace('/(<(?:a|area).*?href=")(#[^"]*")/i', '${1}' . htmlspecialchars($scriptPath) . '${2}', $originalContent);
// There was an error in the call to preg_replace, so keep the original content (behavior prior to PHP 5.2)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment