Skip to content
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

fix(browser): restrict served files from /__screenshot-error #7340

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading