Skip to content

Commit

Permalink
Sanitize skin urls that could be used for XSS (#4654)
Browse files Browse the repository at this point in the history
Co-authored-by: kiatng <[email protected]>
  • Loading branch information
colinmollenhour and kiatng authored Feb 26, 2025
1 parent a1dbce2 commit d307e5b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/code/core/Mage/Core/Model/Design/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ public function getSkinBaseUrl(array $params = [])
{
$params['_type'] = 'skin';
$this->updateParamDefaults($params);
return Mage::getBaseUrl('skin', isset($params['_secure']) ? (bool) $params['_secure'] : null)
. $params['_area'] . '/' . $params['_package'] . '/' . $params['_theme'] . '/';
$urlPath = $params['_area'] . '/' . $params['_package'] . '/' . $params['_theme'] . '/';
// Prevent XSS through malformed configuration
$urlPath = htmlspecialchars($urlPath, ENT_HTML5 | ENT_QUOTES, 'UTF-8');
return Mage::getBaseUrl('skin', isset($params['_secure']) ? (bool) $params['_secure'] : null) . $urlPath;
}

/**
Expand Down Expand Up @@ -524,7 +526,8 @@ public function getSkinUrl($file = null, array $params = [])
}
$this->updateParamDefaults($params);
if (!empty($file)) {
$result = $this->_fallback(
// This updates $params with the base package and default theme if the file is not found
$this->_fallback(
$file,
$params,
$this->_fallback->getFallbackScheme(
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Core/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
</template_ua_regexp>
<skin translate="label">
<label>Skin (Images / CSS)</label>
<validate>validate-no-html-tags</validate>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
var BLANK_URL = '<?php echo $this->getJsUrl() ?>blank.html';
var BLANK_IMG = '<?php echo $this->getJsUrl() ?>spacer.gif';
var BASE_URL = '<?php echo $this->getUrl('*') ?>';
var SKIN_URL = '<?php echo $this->jsQuoteEscape($this->getSkinUrl()) ?>';
var SKIN_URL = '<?php echo $this->getSkinUrl() ?>';
var FORM_KEY = '<?php echo $this->getFormKey() ?>';
//]]>
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
<link rel="icon" href="<?php echo $this->getSkinUrl('favicon.ico') ?>" type="image/x-icon"/>

<script type="text/javascript">
//<![CDATA[
var BLANK_URL = '<?php echo $this->getJsUrl() ?>blank.html';
var BLANK_IMG = '<?php echo $this->getJsUrl() ?>spacer.gif';
var BASE_URL = '<?php echo $this->getUrl('*') ?>';
var SKIN_URL = '<?php echo $this->jsQuoteEscape($this->getSkinUrl()) ?>';
var SKIN_URL = '<?php echo $this->getSkinUrl() ?>';
var FORM_KEY = '<?php echo $this->getFormKey() ?>';
<?php # BC: cast to INT in case of non-existing method getLoadingTimeout() in 3rd-party code?>
var LOADING_TIMEOUT = <?php echo (int)$this->getLoadingTimeout() ?>;
//]]>
</script>

<?php echo $this->getCssJsHtml() ?>
Expand Down

0 comments on commit d307e5b

Please sign in to comment.