Fix crash in secret scanning middleware for invalid versions (#58792)
This commit is contained in:
@@ -30,6 +30,10 @@ export default async function secretScanning(
|
|||||||
|
|
||||||
const { isEnterpriseCloud, isEnterpriseServer } = getVersionInfo(currentVersion)
|
const { isEnterpriseCloud, isEnterpriseServer } = getVersionInfo(currentVersion)
|
||||||
|
|
||||||
|
if (isEnterpriseServer && !allVersions[currentVersion]) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
const versionPath = isEnterpriseCloud
|
const versionPath = isEnterpriseCloud
|
||||||
? 'ghec'
|
? 'ghec'
|
||||||
: isEnterpriseServer
|
: isEnterpriseServer
|
||||||
|
|||||||
@@ -17,4 +17,12 @@ describe('secret-scanning pipeline', () => {
|
|||||||
const page = await get(`/${targetFilename}`, { followRedirects: true })
|
const page = await get(`/${targetFilename}`, { followRedirects: true })
|
||||||
expect(page.statusCode).toBe(200)
|
expect(page.statusCode).toBe(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should not crash on malformed URL with double version', async () => {
|
||||||
|
const url =
|
||||||
|
'/en/enterprise-server@3.11/enterprise-cloud@latest/code-security/secret-scanning/introduction/supported-secret-scanning-patterns'
|
||||||
|
const res = await get(url)
|
||||||
|
// It should probably be a 404 because the URL is invalid, but definitely not a 500
|
||||||
|
expect(res.statusCode).not.toBe(500)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user