Skip to content

Potential fix for code scanning alert no. 93: DOM text reinterpreted as HTML#160

Merged
juliuskrah merged 2 commits into
mainfrom
alert-autofix-93
May 15, 2026
Merged

Potential fix for code scanning alert no. 93: DOM text reinterpreted as HTML#160
juliuskrah merged 2 commits into
mainfrom
alert-autofix-93

Conversation

@juliuskrah
Copy link
Copy Markdown
Contributor

Potential fix for https://github.com/gitstore-dev/GitStore/security/code-scanning/93

Use a proven HTML sanitizer on the rendered markdown output before passing it to dangerouslySetInnerHTML.
Best fix with minimal behavior change:

  1. In gitstore-admin/src/components/shared/MarkdownEditor.tsx, import DOMPurify.
  2. Keep existing markdown conversion logic.
  3. Sanitize renderMarkdown(value) result using DOMPurify.sanitize(...).
  4. Use sanitized string in dangerouslySetInnerHTML.

This addresses all variants because all tainted flows converge at the same sink in MarkdownEditor.

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

…as HTML

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@juliuskrah juliuskrah marked this pull request as ready for review May 15, 2026 10:21
@juliuskrah juliuskrah enabled auto-merge May 15, 2026 10:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c13c37a7e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Copyright (c) 2026 GitStore contributors

import React, { useState } from 'react';
import DOMPurify from 'dompurify';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the new sanitizer package to admin dependencies

This change introduces import DOMPurify from 'dompurify', but gitstore-admin/package.json and package-lock.json do not include dompurify, so a clean install/build of the admin app cannot resolve this module and will fail at compile/bundle time. Because CI and new environments rely on declared dependencies, this breaks the feature universally until the dependency is added and locked.

Useful? React with 👍 / 👎.

return html;
};

const sanitizedPreviewHtml = DOMPurify.sanitize(renderMarkdown(value));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid sanitizing markdown when preview is hidden

Computing sanitizedPreviewHtml unconditionally causes renderMarkdown(value) and DOMPurify.sanitize(...) to run on every render, including normal typing mode when preview is off. Previously this work happened only in the preview branch, so this introduces avoidable per-keystroke overhead that can noticeably slow editing for larger markdown inputs.

Useful? React with 👍 / 👎.

@juliuskrah juliuskrah disabled auto-merge May 15, 2026 10:25
@juliuskrah juliuskrah added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit ee679d9 May 15, 2026
14 of 15 checks passed
@juliuskrah juliuskrah deleted the alert-autofix-93 branch May 15, 2026 13:21
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