Skip to content

Potential fix for code scanning alert no. 6: Bad HTML filtering regexp - #2

Merged
f1anderz merged 4 commits into
mainfrom
alert-autofix-6
Jul 27, 2026
Merged

Potential fix for code scanning alert no. 6: Bad HTML filtering regexp#2
f1anderz merged 4 commits into
mainfrom
alert-autofix-6

Conversation

@f1anderz

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/f1anderz/msg-parser/security/code-scanning/6

Найкращий практичний підхід — використовувати перевірену sanitizer-бібліотеку (наприклад DOMPurify), але в межах наданого фрагмента без додавання зовнішньої залежності треба мінімально й безпечно виправити regex, щоб він видаляв також “помилкові, але прийнятні браузером” варіанти закривального script-тега.

Оптимальна точкова правка в reference/msg-preview.js (рядок з .replace(/<script\b[\s\S]*?<\/script\s*>/gi, '')):
замінити шаблон на такий, що дозволяє будь-які символи, крім >, між script і > у закривальному тезі:

  • було: </script\s*>
  • стане: </script\b[^>]*>

Це покриє </script foo="bar">, </script\t\n bar> тощо, не змінюючи решту поведінки функції.

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

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread reference/msg-preview.js Fixed
…racter sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread reference/msg-preview.js Fixed
Comment thread reference/msg-preview.js Fixed
…racter sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread reference/msg-preview.js Fixed
…racter sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@f1anderz
f1anderz marked this pull request as ready for review July 27, 2026 15:00
@f1anderz
f1anderz merged commit ebbb558 into main Jul 27, 2026
4 checks passed
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