Skip to content

Commit

Permalink
fix(browser): restrict served files from /__screenshot-error (#7340)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Jan 23, 2025
1 parent 45085cf commit ed9aeba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
}

const url = new URL(req.url, 'http://localhost')
const file = url.searchParams.get('file')
const id = url.searchParams.get('id')
if (!id) {
res.statusCode = 404
res.end()
return
}

const task = parentServer.vitest.state.idMap.get(id)
const file = task?.meta.failScreenshotPath
if (!file) {
res.statusCode = 404
res.end()
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/client/components/views/ViewReport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ const showScreenshot = ref(false)
const timestamp = ref(Date.now())
const currentTask = ref<Task | undefined>()
const currentScreenshotUrl = computed(() => {
const file = currentTask.value?.meta.failScreenshotPath
const id = currentTask.value?.id
// force refresh
const t = timestamp.value
// browser plugin using /, change this if base can be modified
return file ? `/__screenshot-error?file=${encodeURIComponent(file)}&t=${t}` : undefined
return id ? `/__screenshot-error?id=${encodeURIComponent(id)}&t=${t}` : undefined
})
function showScreenshotModal(task: Task) {
Expand Down

0 comments on commit ed9aeba

Please sign in to comment.