Skip to content

Commit ed9aeba

Browse files
authored
fix(browser): restrict served files from /__screenshot-error (#7340)
1 parent 45085cf commit ed9aeba

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/browser/src/node/plugin.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
9393
}
9494

9595
const url = new URL(req.url, 'http://localhost')
96-
const file = url.searchParams.get('file')
96+
const id = url.searchParams.get('id')
97+
if (!id) {
98+
res.statusCode = 404
99+
res.end()
100+
return
101+
}
102+
103+
const task = parentServer.vitest.state.idMap.get(id)
104+
const file = task?.meta.failScreenshotPath
97105
if (!file) {
98106
res.statusCode = 404
99107
res.end()

packages/ui/client/components/views/ViewReport.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ const showScreenshot = ref(false)
116116
const timestamp = ref(Date.now())
117117
const currentTask = ref<Task | undefined>()
118118
const currentScreenshotUrl = computed(() => {
119-
const file = currentTask.value?.meta.failScreenshotPath
119+
const id = currentTask.value?.id
120120
// force refresh
121121
const t = timestamp.value
122122
// browser plugin using /, change this if base can be modified
123-
return file ? `/__screenshot-error?file=${encodeURIComponent(file)}&t=${t}` : undefined
123+
return id ? `/__screenshot-error?id=${encodeURIComponent(id)}&t=${t}` : undefined
124124
})
125125
126126
function showScreenshotModal(task: Task) {

0 commit comments

Comments
 (0)