Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

πŸ›‘οΈ Sentinel: [HIGH] Fix XSS vulnerability in JsonParser#1767

Draft
google-labs-jules[bot] wants to merge 3 commits intodevelopunipept/unipept:developfrom
sentinel-fix-xss-jsonparser-15725120700481537122unipept/unipept:sentinel-fix-xss-jsonparser-15725120700481537122Copy head branch name to clipboard
Draft

πŸ›‘οΈ Sentinel: [HIGH] Fix XSS vulnerability in JsonParser#1767
google-labs-jules[bot] wants to merge 3 commits intodevelopunipept/unipept:developfrom
sentinel-fix-xss-jsonparser-15725120700481537122unipept/unipept:sentinel-fix-xss-jsonparser-15725120700481537122Copy head branch name to clipboard

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

I have identified and fixed a stored XSS vulnerability in the JsonParser class, which is used to syntax-highlight JSON objects in the UI.

Vulnerability

The JsonParser.parseAndHighlight method was constructing HTML strings from JSON objects without escaping HTML special characters in string values or keys. If an attacker could inject malicious content (e.g., <script>alert(1)</script>) into data that is subsequently displayed using this parser and rendered with v-html, the script would execute.

Fix

I modified src/logic/parsers/json/JsonParser.ts to:

  1. Add a helper method escapeHtml that escapes &, <, >, ", and '.
  2. Apply this escaping to both JSON keys (after stripping quotes) and string values before wrapping them in syntax-highlighting <span> tags.

Verification

I updated src/logic/parsers/json/JsonParser.spec.ts to:

  1. Reflect that string values are now HTML-escaped (e.g., &quot;test&quot; instead of "test").
  2. Add a new test case explicitly checking that a malicious payload (<img src=x onerror=alert(1)>) is properly escaped and does not appear raw in the output.

All tests passed. yarn lint also passed.


PR created automatically by Jules for task 15725120700481537122 started by @pverscha

The `JsonParser` class was using `JSON.stringify` and regex replacement to generate HTML for syntax highlighting, but it failed to escape HTML special characters in the string values or object keys. This could allow XSS attacks if the input object contained malicious strings (e.g. `<script>`) and the result was rendered via `v-html`.

This commit:
- Adds a private `escapeHtml` method to `JsonParser`.
- Updates `parseAndHighlight` to escape both object keys (after stripping quotes) and string values.
- Updates unit tests to expect escaped HTML entities (e.g. `&quot;`).
- Adds a specific test case to verify that malicious scripts are escaped.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@pverscha
Copy link
Copy Markdown
Member

Instead of trying to sanitize the generated HTML from JSON ourselves, I think it might be better if we use the dompurify dependency to do the job for us. This dependency is already present in this project, can you adjust?

@google-labs-jules
Copy link
Copy Markdown
Contributor Author

Instead of trying to sanitize the generated HTML from JSON ourselves, I think it might be better if we use the dompurify dependency to do the job for us. This dependency is already present in this project, can you adjust?

Thank you for the suggestion. I have updated the implementation to use dompurify for sanitization. I have also configured it to allow span tags and style attributes, which are necessary for the syntax highlighting to function correctly. Additionally, I've updated the tests to run in a jsdom environment and verified that malicious tags are now stripped.

Replaced the custom regex-based HTML escaping with `dompurify` as requested.
This ensures more robust sanitization of the generated HTML.

Changes:
- Import `dompurify` in `JsonParser.ts`.
- Wrap the generated HTML string in `DOMPurify.sanitize()`, allowing `span` tags and `style` attributes.
- Update `JsonParser.spec.ts` to use `jsdom` environment (required for DOMPurify) and update test expectations to reflect that malicious tags are stripped rather than escaped.
@pverscha
Copy link
Copy Markdown
Member

Is it really required to add the jsdom dependency for this PR? I'd rather not introduce yet another dependency to the project.

@google-labs-jules
Copy link
Copy Markdown
Contributor Author

Is it really required to add the jsdom dependency for this PR? I'd rather not introduce yet another dependency to the project.

You are right, we can avoid adding jsdom as a dev dependency. I have removed it and updated the unit tests to mock dompurify instead. This verifies that DOMPurify.sanitize is called correctly without needing a full DOM environment in the tests.

- Use `dompurify` to sanitize generated HTML.
- Mock `dompurify` in unit tests to avoid `jsdom` dependency.
- Remove `jsdom` from devDependencies.

Co-authored-by: pverscha <9608686+pverscha@users.noreply.github.com>
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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.