File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515import { getIntegrations } from '@/packages/lib/config'
1616
1717const VULTR_API_BASE = 'https://api.vultr.com/v2'
18+ const VULTR_API_BASE_URL = new URL ( VULTR_API_BASE )
1819
1920function 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
3050async function getApiKey ( ) : Promise < string > {
You can’t perform that action at this time.
0 commit comments