Skip to content

Commit aa4beed

Browse files
committed
fix(browser): restrict served files from /__screenshot-error (vitest-dev#7340)
1 parent 5c45d06 commit aa4beed

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/browser/src/node/plugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ export default (browserServer: BrowserServer, base = '/'): Plugin[] => {
125125
}
126126

127127
const url = new URL(req.url, 'http://localhost')
128-
const file = url.searchParams.get('file')
128+
const id = url.searchParams.get('id')
129+
if (!id) {
130+
res.statusCode = 404
131+
res.end()
132+
return
133+
}
134+
135+
const task = parentServer.vitest.state.idMap.get(id)
136+
const file = task?.meta.failScreenshotPath
129137
if (!file) {
130138
res.statusCode = 404
131139
res.end()

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

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

0 commit comments

Comments
 (0)