Skip to content

Conversation

@PDowney
Copy link
Collaborator

@PDowney PDowney commented Jul 4, 2025

Potential fix for https://github.com/EngineScript/EngineScript/security/code-scanning/14

To fix the issue, the sanitization logic should be updated to repeatedly apply the regular expression replacements until no further matches are found. This ensures that all instances of the targeted patterns, including multiple consecutive occurrences, are removed. The sanitizeLogContent method should be modified to use a loop that applies the replacements iteratively until the input string remains unchanged. This approach is consistent with best practices for handling incomplete multi-character sanitization.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ter sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Jul 4, 2025

Thanks for contributing to EngineScript! 🎉

If your PR fixes an issue or relates to a specific environment, please consider including the sanitized output
of es.debug to show the environment where you tested your changes.
Remember to remove any sensitive information before sharing.

We'll review your PR soon!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 4, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@PDowney PDowney marked this pull request as ready for review July 4, 2025 06:26
Copilot AI review requested due to automatic review settings July 4, 2025 06:26
Comment on lines +899 to +905
input = 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

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the sanitizeLogContent method to iteratively apply regex replacements until no further matches remain, then enforces a maximum length.

  • Wraps the replace chain in a do/while loop to handle consecutive patterns
  • Moves the 50,000-character substring limit to after all sanitization passes
Comments suppressed due to low confidence (1)

config/var/www/admin/control-panel/dashboard.js:897

  • There are no tests covering cases with multiple consecutive occurrences of malicious patterns. Please add unit tests for sanitizeLogContent to validate that repeated matches are fully removed.
        do {

Comment on lines 895 to +899
// 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
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.
@PDowney PDowney merged commit b751e2b into master Jul 4, 2025
8 of 10 checks passed
@github-actions github-actions bot deleted the alert-autofix-14 branch July 4, 2025 06:27
@github-actions
Copy link

github-actions bot commented Jul 4, 2025

🎉 EngineScript Nginx Build Test PASSED 🎉

Nginx core component built successfully:

  • Nginx: ✅ Success

✅ Ready for deployment testing!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants