Skip to content

fix(ncp-web): prevent XSS via log output and undefined array key warning#2096

Open
aroldobossoni wants to merge 1 commit intonextcloud:masterfrom
aroldobossoni:fix/xss-and-undefined-http-accept-language
Open

fix(ncp-web): prevent XSS via log output and undefined array key warning#2096
aroldobossoni wants to merge 1 commit intonextcloud:masterfrom
aroldobossoni:fix/xss-and-undefined-http-accept-language

Conversation

@aroldobossoni
Copy link

Summary

This PR fixes two issues in the NextCloudPi web panel that can cause the admin dashboard to fail loading:

1. XSS vulnerability / HTML parser breakage via ncp.log content

Problem: When /var/log/ncp.log contains HTML-like strings (e.g., <strftime_format> from backup operations), the unescaped output in index.php breaks the browser's HTML parser. This causes:

  • The browser to treat log content as HTML tags
  • Subsequent <script> tags to be ignored
  • minified.js and ncp.js never execute
  • Dashboard shows infinite "System Info" loading spinner

Fix: Wrap file_get_contents('/var/log/ncp.log') with htmlspecialchars(..., ENT_QUOTES, 'UTF-8') to properly escape HTML entities.

2. PHP warning for undefined HTTP_ACCEPT_LANGUAGE array key

Problem: When HTTP requests lack the Accept-Language header (common with API calls, curl, automated scripts), PHP emits an "Undefined array key" warning. In ncp-launcher.php, this warning can corrupt JSON responses.

Fix: Use PHP's null coalescing operator (?? '') to provide a default empty string when the header is missing.

Files Changed

  • ncp-web/index.php (lines 68, 290)
  • ncp-web/ncp-launcher.php (line 24)

Testing

Tested on NextCloudPi running in an LXC container on Proxmox. After applying these fixes:

  • Dashboard loads correctly even with HTML-like content in logs
  • No PHP warnings in Apache error logs for missing Accept-Language header
  • All existing functionality remains intact

Related Issues

This addresses a real-world issue where users see an infinite loading spinner on the "System Info" section of the NCP admin panel.

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
Copy link

@baryah baryah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these modifications did work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants