Skip to content
Merged
Prev Previous commit
Next Next commit
fix: Fix false-positive psalm taint errors when outputting plain text
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Feb 17, 2025
commit 640dbd0b5e38ef603c4edcc646ed7df8117c9963
8 changes: 0 additions & 8 deletions build/psalm-baseline-security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@
<code><![CDATA[$sqliteFile]]></code>
</TaintedFile>
</file>
<file src="lib/private/legacy/OC_Template.php">
<TaintedHtml>
<code><![CDATA[$exception->getTraceAsString()]]></code>
</TaintedHtml>
<TaintedTextWithQuotes>
<code><![CDATA[$exception->getTraceAsString()]]></code>
</TaintedTextWithQuotes>
</file>
<file src="lib/public/DB/QueryBuilder/IQueryBuilder.php">
<TaintedSql>
<code><![CDATA[$column]]></code>
Expand Down
12 changes: 10 additions & 2 deletions lib/private/legacy/OC_Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,15 @@ public static function printExceptionErrorPage($exception, $statusCode = 503) {
die();
}

private static function printPlainErrorPage(\Throwable $exception, bool $debug = false) {
/**
* @psalm-taint-escape has_quotes
* @psalm-taint-escape html
*/
private static function fakeEscapeForPlainText(string $str): string {
return $str;
}

private static function printPlainErrorPage(\Throwable $exception, bool $debug = false): void {
header('Content-Type: text/plain; charset=utf-8');
print("Internal Server Error\n\n");
print("The server encountered an internal error and was unable to complete your request.\n");
Expand All @@ -323,7 +331,7 @@ private static function printPlainErrorPage(\Throwable $exception, bool $debug =
if ($debug) {
print("\n");
print($exception->getMessage() . ' ' . $exception->getFile() . ' at ' . $exception->getLine() . "\n");
print($exception->getTraceAsString());
print(self::fakeEscapeForPlainText($exception->getTraceAsString()));
}
}
}