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)
|
||||
|
||||
if (isEnterpriseServer && !allVersions[currentVersion]) {
|
||||
return next()
|
||||
}
|
||||
|
||||
const versionPath = isEnterpriseCloud
|
||||
? 'ghec'
|
||||
: isEnterpriseServer
|
||||
|
||||
@@ -17,4 +17,12 @@ describe('secret-scanning pipeline', () => {
|
||||
const page = await get(`/${targetFilename}`, { followRedirects: true })
|
||||
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