Merge remote-tracking branch 'security/3.5.4' into 3.6.0

This commit is contained in:
Daniel Hensby 2017-05-29 01:21:22 +01:00
commit eaee3b6a8b
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 29 additions and 12 deletions

View File

@ -12,7 +12,7 @@ addons:
env:
global:
- CORE_RELEASE=3
- CORE_RELEASE=3.5
matrix:
include:

View File

@ -470,10 +470,6 @@ class CMSPageHistoryController extends CMSMain {
"Version" => $fromVersion,
));
foreach($form->Fields()->dataFields() as $field) {
$field->dontEscape = true;
}
return $form;
}

View File

@ -106,13 +106,23 @@ class RedirectorPage extends Page {
public function onBeforeWrite() {
parent::onBeforeWrite();
// Prefix the URL with "http://" if no prefix is found
if(
$this->ExternalURL
&& !parse_url($this->ExternalURL, PHP_URL_SCHEME)
&& !preg_match('#^//#', $this->ExternalURL)
) {
$this->ExternalURL = 'http://' . $this->ExternalURL;
if ($this->ExternalURL && substr($this->ExternalURL, 0, 2) !== '//') {
$urlParts = parse_url($this->ExternalURL);
if ($urlParts) {
if (empty($urlParts['scheme'])) {
// no scheme, assume http
$this->ExternalURL = 'http://' . $this->ExternalURL;
} elseif (!in_array($urlParts['scheme'], array(
'http',
'https',
))) {
// we only allow http(s) urls
$this->ExternalURL = '';
}
} else {
// malformed URL to reject
$this->ExternalURL = '';
}
}
}

View File

@ -80,6 +80,17 @@ class RedirectorPageTest extends FunctionalTest {
RedirectorPage_Controller::remove_extension('RedirectorPageTest_RedirectExtension');
}
public function testNoJSLinksAllowed()
{
$page = new RedirectorPage();
$js = 'javascript:alert("hello world")';
$page->ExternalURL = $js;
$this->assertEquals($js, $page->ExternalURL);
$page->write();
$this->assertEmpty($page->ExternalURL);
}
}
class RedirectorPageTest_RedirectExtension extends Extension implements TestOnly {