Skip to content

fix(security): 2 improvements across 2 files#1859

Open
tomaioo wants to merge 4 commits into
apollographql:mainfrom
tomaioo:fix/security/regular-expression-injection-redos-risk-
Open

fix(security): 2 improvements across 2 files#1859
tomaioo wants to merge 4 commits into
apollographql:mainfrom
tomaioo:fix/security/regular-expression-injection-redos-risk-

Conversation

@tomaioo

@tomaioo tomaioo commented Apr 24, 2026

Copy link
Copy Markdown

Summary

fix(security): 2 improvements across 2 files

Problem

Severity: Medium | File: src/application/components/HighlightMatch.tsx:L7

HighlightMatch builds a RegExp directly from searchTerm (new RegExp(searchTerm, "i")). If searchTerm is 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 in try/catch to prevent crashes.

Changes

  • src/application/components/HighlightMatch.tsx (modified)
  • src/application/components/ObjectViewer/ObjectKey.tsx (modified)

tomaioo added 2 commits April 23, 2026 23:22
- 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 tomaioo requested a review from a team as a code owner April 24, 2026 06:22
@apollo-cla

Copy link
Copy Markdown

@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 jerelmiller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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, "\\$&")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Suggested change
character.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
RegExp.escape(character)

return <>{value}</>;
}

const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const escapedSearchTerm = RegExp.escape(searchTerm);

@relativeci

relativeci Bot commented Apr 24, 2026

Copy link
Copy Markdown

#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  Change 1 change Regression 1 regression
                 Current
#2025
     Baseline
#2022
Regression  Initial JS 1.73MiB(+0.01%) 1.73MiB
No change  Initial CSS 0B 0B
No change  Cache Invalidation 78.88% 78.88%
No change  Chunks 5 5
No change  Assets 237 237
No change  Modules 1529 1529
No change  Duplicate Modules 134 134
No change  Duplicate Code 5.69% 5.69%
No change  Packages 180 180
No change  Duplicate Packages 12 12
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#2025
     Baseline
#2022
Regression  JS 1.73MiB (+0.01%) 1.73MiB
No change  Other 251.83KiB 251.83KiB
No change  IMG 35.85KiB 35.85KiB
No change  HTML 857B 857B

Bundle analysis reportBranch tomaioo:fix/security/regular-exp...Project dashboard


Generated by RelativeCIDocumentationReport issue

@pkg-pr-new

pkg-pr-new Bot commented Apr 24, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/apollo-client-devtools@1859
npm i https://pkg.pr.new/@apollo/client-devtools-vscode@1859

commit: c10b16d

tomaioo added 2 commits April 24, 2026 17:21
…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>
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.

3 participants