fix(security): 2 improvements across 2 files#1859
Conversation
- Security: Regular expression injection / ReDoS risk from unescaped search input - Security: Regex construction from unescaped characters in ObjectKey renderer Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
- Security: Regular expression injection / ReDoS risk from unescaped search input - Security: Regex construction from unescaped characters in ObjectKey renderer Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
|
@tomaioo: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
jerelmiller
left a comment
There was a problem hiding this comment.
I'd love to use RegExp.escape, otherwise this looks good.
Before I accept this, can you sign the CLA please?
| ? new RegExp( | ||
| `(${softWrapCharacters | ||
| .map((character) => | ||
| character.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") |
There was a problem hiding this comment.
I'd love to use RegExp.escape if we could. That supports Chrome and Firefox versions that have been out for a year so I think its pretty safe to use it at this point in the extension. Can you update these to RegExp.escape?
| character.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") | |
| RegExp.escape(character) |
| return <>{value}</>; | ||
| } | ||
|
|
||
| const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
There was a problem hiding this comment.
| const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | |
| const escapedSearchTerm = RegExp.escape(searchTerm); |
#2025 Bundle Size — 2.01MiB (~+0.01%).c10b16d(current) vs b8b6f7c main#2022(baseline) Warning Bundle contains 16 duplicate packages – View duplicate packages Bundle metrics
Bundle size by type
Bundle analysis report Branch tomaioo:fix/security/regular-exp... Project dashboard Generated by RelativeCI Documentation Report issue |
commit: |
…s://developer.mozilla. Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
const escapedSearchTerm = RegExp.escape(sear Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Summary
fix(security): 2 improvements across 2 files
Problem
Severity:
Medium| File:src/application/components/HighlightMatch.tsx:L7HighlightMatchbuilds aRegExpdirectly fromsearchTerm(new RegExp(searchTerm, "i")). IfsearchTermis user-controlled, attackers can supply regex metacharacters to trigger expensive backtracking (ReDoS) or runtime exceptions (invalid regex), causing UI freezes or crashes.Solution
Escape user input before creating a regex (e.g.,
searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")), enforce max input length, and wrap regex creation intry/catchto prevent crashes.Changes
src/application/components/HighlightMatch.tsx(modified)src/application/components/ObjectViewer/ObjectKey.tsx(modified)