Skip to content

Commit efeec6a

Browse files
fix(ncp-web): prevent XSS via log output and undefined array key warning (#2101)
This commit addresses two issues in the NextCloudPi web panel: 1. HTML injection via ncp.log content (XSS vulnerability) - When /var/log/ncp.log contains HTML-like content (e.g., <strftime_format> from certain backup operations), the unescaped output breaks the HTML parser - This causes the browser to ignore subsequent <script> tags, preventing minified.js and ncp.js from loading - Result: the dashboard never loads and shows infinite "System Info" spinner - Fix: wrap file_get_contents() with htmlspecialchars() in index.php line 290 2. PHP warning for undefined HTTP_ACCEPT_LANGUAGE - When requests lack Accept-Language header (e.g., API calls, curl), PHP emits "Undefined array key" warning - This warning can corrupt JSON responses from ncp-launcher.php - Fix: use null coalescing operator (?? '') in both index.php and ncp-launcher.php Tested on NextCloudPi running in LXC container on Proxmox. Made-with: Cursor Co-authored-by: Aroldo de Mattos Bossoni <github@bossone.com.br>
2 parents e0e9527 + 658157d commit efeec6a

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

ncp-web/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<?php
6666
require("L10N.php");
6767
try {
68-
$l = new L10N($_SERVER["HTTP_ACCEPT_LANGUAGE"], $l10nDir, $modules_path);
68+
$l = new L10N(($_SERVER["HTTP_ACCEPT_LANGUAGE"] ?? ''), $l10nDir, $modules_path);
6969
} catch (Exception $e) {
7070
die("<p class='error'>Error while loading localizations!</p>");
7171
}
@@ -287,7 +287,7 @@
287287
<div id="logs-wrapper" class="content-box <?php if(!array_key_exists('app',$_GET) || (array_key_exists('app',$_GET) && $_GET['app'] != 'logs')) echo 'hidden';?>">
288288
<h2 class="text-title"><?php echo $l->__("NextcloudPi logs"); ?></h2>
289289
<div id="logs-content" class="table-wrapper">
290-
<div id="logs-details-box" class="outputbox"><?php echo str_replace(array("\r\n", "\n", "\r"), '<br/>', file_get_contents('/var/log/ncp.log')) ?></div>
290+
<div id="logs-details-box" class="outputbox"><?php echo str_replace(array("\r\n", "\n", "\r"), '<br/>', htmlspecialchars(file_get_contents('/var/log/ncp.log'), ENT_QUOTES, 'UTF-8')) ?></div>
291291
<div id="log-download-btn-wrapper"><input id="log-download-btn" type="button" value="Download"/></div>
292292
</div>
293293
</div>

ncp-web/ncp-launcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//
2222
require("L10N.php");
2323
try {
24-
$l = new L10N($_SERVER["HTTP_ACCEPT_LANGUAGE"], $l10nDir, $cfg_dir);
24+
$l = new L10N(($_SERVER["HTTP_ACCEPT_LANGUAGE"] ?? ''), $l10nDir, $cfg_dir);
2525
} catch (Exception $e) {
2626
die(json_encode("<p class='error'>Error while loading localizations!</p>"));
2727
}

0 commit comments

Comments
 (0)