-
Notifications
You must be signed in to change notification settings - Fork 89
test(extension-id-guard): allow CWS URL matches; mirrors main PR #26263 #26270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,6 +95,7 @@ function listTextFilesRecursively(root: string): string[] { | |||||||||
| ".turbo", | ||||||||||
| ".idea", | ||||||||||
| ".vscode", | ||||||||||
| ".codex-worktrees", | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| const allowedExtensions = new Set([ | ||||||||||
|
|
@@ -196,12 +197,20 @@ describe("Chrome extension allowlist guard", () => { | |||||||||
| expect(new Set(ALLOWED_EXTENSION_ORIGINS)).toEqual(expectedOrigins); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| test("concrete extension IDs appear only in canonical config", () => { | ||||||||||
| test("concrete extension IDs appear only in canonical config or CWS URLs", () => { | ||||||||||
| // The canonical extension ID may also appear in Chrome Web Store URLs | ||||||||||
| // (e.g. chromewebstore.google.com/detail/.../ID) or in documentation | ||||||||||
| // referencing the published extension. Those are acceptable — they | ||||||||||
| // reference the published extension, not duplicate config. We flag | ||||||||||
| // files where the ID appears outside of a CWS URL context. | ||||||||||
| const config = parseCanonicalConfig(); | ||||||||||
| const allFiles = listTextFilesRecursively(repoRoot); | ||||||||||
|
|
||||||||||
| const CWS_URL_PATTERN = | ||||||||||
| /chromewebstore\.google\.com\/detail\/[^/]+\/[a-p]{32}/; | ||||||||||
|
Comment on lines
+209
to
+210
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Missing
Reproduction with two CWS links in one fileGiven content like: After The ID is still present, causing a false positive. With the
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||
|
|
||||||||||
| for (const extensionId of config.allowedExtensionIds) { | ||||||||||
| const matches: string[] = []; | ||||||||||
| const unexpectedMatches: string[] = []; | ||||||||||
| for (const absPath of allFiles) { | ||||||||||
| const relPath = absPath.replace(`${repoRoot}/`, ""); | ||||||||||
| let content: string; | ||||||||||
|
|
@@ -212,11 +221,17 @@ describe("Chrome extension allowlist guard", () => { | |||||||||
| if ((err as NodeJS.ErrnoException).code === "ENOENT") continue; | ||||||||||
| throw err; | ||||||||||
| } | ||||||||||
| if (content.includes(extensionId)) { | ||||||||||
| matches.push(relPath); | ||||||||||
| if (!content.includes(extensionId)) continue; | ||||||||||
| if (relPath === CANONICAL_CONFIG_REL_PATH) continue; | ||||||||||
|
|
||||||||||
| // Strip all CWS URLs and check if the ID still appears — if it | ||||||||||
| // does, the file is using the ID as a standalone config value. | ||||||||||
| const stripped = content.replace(CWS_URL_PATTERN, ""); | ||||||||||
| if (stripped.includes(extensionId)) { | ||||||||||
| unexpectedMatches.push(relPath); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| expect(matches).toEqual([CANONICAL_CONFIG_REL_PATH]); | ||||||||||
| expect(unexpectedMatches).toEqual([]); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new guard intends to allow extension IDs when they only appear inside Chrome Web Store URLs, but
content.replace(CWS_URL_PATTERN, "")uses a non-global regex, so only the first matching URL in a file is removed. If a file contains the same extension ID in multiple CWS links, later occurrences remain andstripped.includes(extensionId)incorrectly flags the file as a violation, causing false CI failures in exactly the scenario this change is trying to permit.Useful? React with 👍 / 👎.