Skip to content

Commit cb2dbf5

Browse files
Potential fix for code scanning alert no. 17: Server-side request forgery
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 12502ad commit cb2dbf5

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

packages/lib/vultr/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { getIntegrations } from '@/packages/lib/config'
1616

1717
const VULTR_API_BASE = 'https://api.vultr.com/v2'
18+
const VULTR_API_BASE_URL = new URL(VULTR_API_BASE)
1819

1920
function buildVultrApiUrl(path: string): string {
2021
if (!path.startsWith('/')) {
@@ -24,7 +25,26 @@ function buildVultrApiUrl(path: string): string {
2425
throw new Error(`Unsafe Vultr API path: "${path}"`)
2526
}
2627

27-
return new URL(path, VULTR_API_BASE).toString()
28+
const url = new URL(path, VULTR_API_BASE_URL)
29+
30+
if (url.origin !== VULTR_API_BASE_URL.origin) {
31+
throw new Error(`Unsafe Vultr API URL origin: "${url.origin}"`)
32+
}
33+
34+
if (!url.pathname.startsWith('/v2/')) {
35+
throw new Error(`Unsafe Vultr API URL path: "${url.pathname}"`)
36+
}
37+
38+
const lowerPath = url.pathname.toLowerCase()
39+
if (
40+
lowerPath.includes('%2e') ||
41+
lowerPath.includes('%2f') ||
42+
lowerPath.includes('%5c')
43+
) {
44+
throw new Error(`Unsafe encoded Vultr API path: "${url.pathname}"`)
45+
}
46+
47+
return url.toString()
2848
}
2949

3050
async function getApiKey(): Promise<string> {

0 commit comments

Comments
 (0)