Skip to content

Commit 649f0fd

Browse files
committed
fix(extension): normalize Sim paths before capture
1 parent 5ce329a commit 649f0fd

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

‎apps/extension/scripts/test-e2e.ts‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,34 @@ try {
673673
await parentCdp.detach()
674674
}
675675
)
676-
await check('Ordinary Sim pages attach without capturing sensitive fields', async () => {
677-
for (const path of ['/workspace/example', '/extension-notes']) {
676+
await check('Ordinary Sim and encoded remote pages attach without sensitive fields', async () => {
677+
for (const url of [
678+
`${origin}/workspace/example`,
679+
`${origin}/extension-notes`,
680+
`${origin}/workspace/%E2%9C%93`,
681+
`${pageOrigin}/ticket/100%done`,
682+
]) {
678683
const before = (await snapshots()).length
679-
await page.goto(`${origin}${path}?token=URL_SECRET#FRAGMENT_SECRET`)
684+
await page.goto(`${url}?token=URL_SECRET#FRAGMENT_SECRET`)
680685
await page.bringToFront()
681686
await capture()
682687
await expect.poll(async () => (await snapshots()).length).toBe(before + 1)
683688
const snapshot = (await snapshots()).at(-1)
684-
assert(snapshot?.url === `${origin}${path}`, 'Sim page URL retained private parameters')
685-
assert(snapshot.text.includes('visible-reference-482'), 'Visible Sim page content is missing')
686-
assert(!snapshot.text.includes('SENTINEL'), 'Sensitive Sim page content was captured')
689+
assert(snapshot?.url === url, 'Page URL retained private parameters')
690+
assert(snapshot.text.includes('visible-reference-482'), 'Visible page content is missing')
691+
assert(!snapshot.text.includes('SENTINEL'), 'Sensitive page content was captured')
687692
}
688693
})
689-
await check('Embedded Sim chat pages cannot capture themselves', async () => {
690-
for (const path of ['/extension', '/extension/workspace', '/extension/o/organization']) {
694+
await check('Embedded chat and malformed Sim paths fail closed', async () => {
695+
for (const path of [
696+
'/extension',
697+
'/extension/workspace',
698+
'/extension/o/organization',
699+
'/%65xtension',
700+
'/%65xtension/workspace',
701+
'/extension%2fworkspace',
702+
'/extension%ZZ/workspace',
703+
]) {
691704
await page.goto(`${origin}/workspace/example`)
692705
await page.bringToFront()
693706
const previous = (await snapshots()).length
@@ -698,8 +711,8 @@ try {
698711
await page.goto(`${origin}${path}`)
699712
await page.bringToFront()
700713
await capture()
701-
await panel.getByRole('status').filter({ hasText: 'Choose a regular web page' }).waitFor()
702-
assert((await snapshots()).length === before, 'Embedded chat was captured')
714+
await panel.getByRole('status').filter({ hasText: 'This page cannot be attached.' }).waitFor()
715+
assert((await snapshots()).length === before, 'An excluded Sim path was captured')
703716
}
704717
})
705718
await check(

‎apps/extension/src/capture.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ export async function captureActivePage(
2121
if (expected && (await digestUrl(tab.url)) !== expected.urlDigest) {
2222
throw new Error('The page changed before reading. Attach it again.')
2323
}
24+
let pathname = url.pathname
25+
if (url.origin === SIM_ORIGIN) {
26+
try {
27+
pathname = decodeURIComponent(pathname)
28+
} catch {
29+
throw new Error('This page cannot be attached.')
30+
}
31+
}
2432
if (
2533
!['http:', 'https:'].includes(url.protocol) ||
2634
(url.origin === SIM_ORIGIN &&
27-
(url.pathname === '/extension' || url.pathname.startsWith('/extension/'))) ||
35+
(pathname === '/extension' || pathname.startsWith('/extension/'))) ||
2836
url.username ||
2937
url.password ||
3038
tab.incognito
3139
) {
32-
throw new Error('Choose a regular web page to attach.')
40+
throw new Error('This page cannot be attached.')
3341
}
3442
const results = await chrome.scripting.executeScript({
3543
target: expected

0 commit comments

Comments
 (0)