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
2 changes: 1 addition & 1 deletion public/themes/material-blue/views/_layouts/main.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use function SP\__;
echo $_e($_getvar('lang')); ?>">
<head>
<title><?php
printf('%s :: %s', $_getvar('app_name'), $_getvar('app_desc')); ?></title>
printf('%s :: %s', $_e($_getvar('app_name')), $_e($_getvar('app_desc'))); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ use function SP\__;
<i class="btn-action material-icons">account_circle</i>
<span id="user-name"><?php echo $_e($_getvar('ctx_userName')); ?></span>
<span for="user-name"
class="mdl-tooltip mdl-tooltip--top"><?php printf('%s : %s', __('Group'), $_getvar('ctx_userGroup')); ?></span>
class="mdl-tooltip mdl-tooltip--top"><?php printf('%s : %s', __('Group'), $_e($_getvar('ctx_userGroup'))); ?></span>
<?php
/** @var IconInterface $ctx_userType */
$ctx_userType = $_getvar('ctx_userType');
Expand Down
2 changes: 1 addition & 1 deletion public/themes/material-blue/views/_partials/footer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use function SP\__;
<?php endif; ?>
<span id="user-name-footer"><?php echo $_e($_getvar('ctx_userName')); ?></span>
<span for="user-name-footer"
class="mdl-tooltip mdl-tooltip--top"><?php printf('%s : %s', __('Group'), $_getvar('ctx_userGroup')); ?></span>
class="mdl-tooltip mdl-tooltip--top"><?php printf('%s : %s', __('Group'), $_e($_getvar('ctx_userGroup'))); ?></span>
</span>
</div>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion public/themes/material-blue/views/account/files-list.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use function SP\__;
echo $_e($file->getName()); ?>">
<i class="material-icons mdl-list__item-icon">attachment</i>
<span><?php
printf('%s (%d KB)', Html::truncate($file->getName() ?? '', 50), ($file->getSize() ?? 0) / 1024); ?></span>
printf('%s (%d KB)', $_e(Html::truncate($file->getName() ?? '', 50)), (int)(($file->getSize() ?? 0) / 1024)); ?></span>
</span>

<span class="list-actions">
Expand Down
2 changes: 1 addition & 1 deletion public/themes/material-blue/views/configManager/info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ use function SP\__;
</tr>
<tr>
<td class="descField"><?php echo __('Download rate'); ?></td>
<td class="valField"><?php printf('%d MB/s', $_getvar('downloadRate')); ?></td>
<td class="valField"><?php printf('%d MB/s', $_e((string)$_getvar('downloadRate'))); ?></td>
</tr>
</table>

Expand Down
2 changes: 1 addition & 1 deletion public/themes/material-blue/views/install/index.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use function SP\__;

<div class="installer-card-header">
<h1><?php
printf('%s %s — %s', $_getvar('app_name'), $_getvar('app_version'), __('Installation')); ?></h1>
printf('%s %s — %s', $_e($_getvar('app_name')), $_e($_getvar('app_version')), __('Installation')); ?></h1>
</div>

<ol class="installer-stepper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $sessionTimeout = $_getvar('sessionTimeout');
class="mdl-textfield__input mdl-color-text--indigo-400"
maxlength="33"
value="<?php
printf('%s/%s', $sessionTimeout->getAddress(), $sessionTimeout->getMask()); ?>">
printf('%s/%s', $_e($sessionTimeout->getAddress()), $_e($sessionTimeout->getMask())); ?>">
<label class="mdl-textfield__label"
for="ip_address"><?php
echo __('IP Address'); ?></label>
Expand Down
8 changes: 4 additions & 4 deletions public/themes/material-blue/views/wiki/wikipage.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ $pageInfo = $_getvar('pageInfo');
printf(
'%s: <a href="%s" target="_blank">%s</a>',
__('Page'),
$_getvar('wikiUrlBase') . '/' . $result['id'],
$result['id']
$_e($_getvar('wikiUrlBase') . '/' . $result['id']),
$_e($result['id'])
); ?></li>
<?php
endforeach; ?>
Expand All @@ -85,8 +85,8 @@ $pageInfo = $_getvar('pageInfo');
printf(
'%s: <a href="%s" target="_blank">%s</a>',
__('Page'),
$_getvar('wikiUrlBase') . $pageInfo['name'],
$pageInfo['name']
$_e($_getvar('wikiUrlBase') . $pageInfo['name']),
$_e($pageInfo['name'])
); ?></li>
<li><?php
printf('%s: %s', __('Date'), $pageInfo['lastModified']); ?></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ class ThemeEscapesWhatItRendersTest extends TestCase
private const THEME = REAL_APP_ROOT . '/public/themes/material-blue/views';

/**
* Every `<?php echo …` / `<?= …` in a template.
* Every `<?php echo …`, `<?= …` and `<?php printf(…)` in a template.
*
* printf() has to be its own branch: `echo|print` requires whitespace after the word, and
* `printf(` has none, so a printf was invisible to this test entirely. That is how the account
* file list came to render an uploaded file's name unescaped — the two title attributes either
* side of it are escaped, and nothing here was looking at the line between them.
*/
private const ECHO = '/<\?(?:php\s+)?(?:echo|print)\s+(.*?)(?:;\s*)?\?>|<\?=\s*(.*?)(?:;\s*)?\?>/s';
private const ECHO = '/<\?(?:php\s+)?(?:echo|print)\s+(.*?)(?:;\s*)?\?>'
. '|<\?(?:php\s+)?v?printf\s*\((.*?)\)\s*(?:;\s*)?\?>'
. '|<\?=\s*(.*?)(?:;\s*)?\?>/s';

/**
* Reads that return text a user or an administrator typed. Deliberately by name: these are the
Expand Down Expand Up @@ -183,7 +190,7 @@ private static function echoesIn(string $template): array
$echoes = [];

foreach ($matches as $match) {
$expression = trim($match[1][0] ?? '') !== '' ? $match[1][0] : ($match[2][0] ?? '');
$expression = self::expressionFrom($match);
$expression = implode(' ', preg_split('/\s+/', trim($expression)) ?: []);

if ($expression !== '') {
Expand All @@ -210,7 +217,7 @@ private static function interpolationsInScripts(string $template): array
preg_match_all(self::ECHO, $script[1][0], $echoes, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);

foreach ($echoes as $echo) {
$expression = trim($echo[1][0] ?? '') !== '' ? $echo[1][0] : ($echo[2][0] ?? '');
$expression = self::expressionFrom($echo);
$expression = implode(' ', preg_split('/\s+/', trim($expression)) ?: []);

if ($expression !== '') {
Expand Down Expand Up @@ -269,4 +276,20 @@ private static function picksBetweenLiterals(string $expression): bool
$expression
);
}

/**
* The expression a match emitted, whichever of ECHO's three branches matched it.
*
* @param array<int, array{0: string, 1: int}> $match
*/
private static function expressionFrom(array $match): string
{
foreach ([1, 2, 3] as $group) {
if (trim($match[$group][0] ?? '') !== '') {
return $match[$group][0];
}
}

return '';
}
}