Skip to content
Merged
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
22 changes: 13 additions & 9 deletions config/var/www/admin/control-panel/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,15 +893,19 @@

// For logs, we allow more characters but still remove dangerous patterns
// Keep line breaks and basic formatting for readability but remove XSS vectors
return input
.replace(/\0/g, '') // Remove null bytes first
.replace(/[<>&"'`]/g, '') // Remove HTML/XML special characters that could break out of attributes
.replace(/javascript:/gi, '') // Remove javascript: protocol
.replace(/data:/gi, '') // Remove data: protocol
.replace(/vbscript:/gi, '') // Remove vbscript: protocol
.replace(/on\w+=/gi, '') // Remove event handlers
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') // Remove control chars but keep \t, \n, \r
.substring(0, 50000); // Reasonable log size limit
let previous;
do {
previous = input;
input = input
Comment on lines 895 to +899
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

The iterative sanitization loop scans the entire input string unbounded until no further changes, which could be expensive for very large inputs. Consider applying the substring limit inside the loop or capping the input length before each iteration to bound work per pass.

Copilot uses AI. Check for mistakes.
.replace(/\0/g, '') // Remove null bytes first
.replace(/[<>&"'`]/g, '') // Remove HTML/XML special characters that could break out of attributes
.replace(/javascript:/gi, '') // Remove javascript: protocol
.replace(/data:/gi, '') // Remove data: protocol
.replace(/vbscript:/gi, '') // Remove vbscript: protocol
.replace(/on\w+=/gi, '') // Remove event handlers
Comment on lines +899 to +905

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
on
, which may cause an HTML attribute injection vulnerability.

Copilot Autofix

AI 7 months ago

To address the issue, the sanitization logic in the sanitizeLogContent method should be updated to ensure that all unsafe patterns are removed effectively. The best approach is to rewrite the regular expression /on\w+=/gi to match individual unsafe characters or patterns, or to use a well-tested sanitization library like sanitize-html for comprehensive sanitization.

In this case, we will rewrite the regular expression to match individual unsafe characters and apply the sanitization repeatedly until no changes occur. This ensures that all instances of unsafe patterns are removed, even in edge cases with overlapping or nested patterns.


Suggested changeset 1
config/var/www/admin/control-panel/dashboard.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/config/var/www/admin/control-panel/dashboard.js b/config/var/www/admin/control-panel/dashboard.js
--- a/config/var/www/admin/control-panel/dashboard.js
+++ b/config/var/www/admin/control-panel/dashboard.js
@@ -904,3 +904,3 @@
                 .replace(/vbscript:/gi, '') // Remove vbscript: protocol
-                .replace(/on\w+=/gi, '') // Remove event handlers
+                .replace(/on(?:\w+|[^\s]*)=/gi, '') // Remove event handlers and unsafe attribute patterns
                 .replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ''); // Remove control chars but keep \t, \n, \r
EOF
@@ -904,3 +904,3 @@
.replace(/vbscript:/gi, '') // Remove vbscript: protocol
.replace(/on\w+=/gi, '') // Remove event handlers
.replace(/on(?:\w+|[^\s]*)=/gi, '') // Remove event handlers and unsafe attribute patterns
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ''); // Remove control chars but keep \t, \n, \r
Copilot is powered by AI and may make mistakes. Always verify output.
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ''); // Remove control chars but keep \t, \n, \r
} while (input !== previous);
return input.substring(0, 50000); // Reasonable log size limit
}

setTextContent(elementId, content) {
Expand Down
Loading