未验证 提交 0f0398c8 编写于 作者: T Tim Neutkens 提交者: GitHub

Make sure to error when setting too large of preview data (#10831)

* Make sure to error when setting too large of preview data

* Update to check size after signing and limit to 2KB
上级 a4eef950
......@@ -377,6 +377,14 @@ function setPreviewData<T>(
}
)
// limit preview mode cookie to 2KB since we shouldn't store too much
// data here and browsers drop cookies over 4KB
if (payload.length > 2048) {
throw new Error(
`Preview data is limited to 2KB currently, reduce how much data you are storing as preview data to continue`
)
}
const { serialize } = require('cookie') as typeof import('cookie')
const previous = res.getHeader('Set-Cookie')
res.setHeader(`Set-Cookie`, [
......
export default (req, res) => {
res.setPreviewData(req.query)
if (req.query.tooBig) {
try {
res.setPreviewData(new Array(2000).fill('a').join(''))
} catch (err) {
return res.status(500).end('too big')
}
} else {
res.setPreviewData(req.query)
}
res.status(200).end()
}
......@@ -156,6 +156,12 @@ function runTests(startServer = nextStart) {
expect(cookies[1]).not.toHaveProperty('Max-Age')
})
it('should throw error when setting too large of preview data', async () => {
const res = await fetchViaHTTP(appPort, '/api/preview?tooBig=true')
expect(res.status).toBe(500)
expect(await res.text()).toBe('too big')
})
/** @type import('next-webdriver').Chain */
let browser
it('should start the client-side browser', async () => {
......
export default (req, res) => {
res.setPreviewData(req.query)
if (req.query.tooBig) {
try {
res.setPreviewData(new Array(2000).fill('a').join(''))
} catch (err) {
return res.status(500).end('too big')
}
} else {
res.setPreviewData(req.query)
}
res.status(200).end()
}
......@@ -63,6 +63,12 @@ function runTests(startServer = nextStart) {
expect(pre).toBe('undefined and undefined')
})
it('should throw error when setting too large of preview data', async () => {
const res = await fetchViaHTTP(appPort, '/api/preview?tooBig=true')
expect(res.status).toBe(500)
expect(await res.text()).toBe('too big')
})
let previewCookieString
it('should enable preview mode', async () => {
const res = await fetchViaHTTP(appPort, '/api/preview', { lets: 'goooo' })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册