File tree 2 files changed +24
-10
lines changed
2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -34,14 +34,28 @@ describe('request', () => {
34
34
} )
35
35
} )
36
36
37
- describe ( 'createRequest' , async ( ) => {
38
- const api = createRequest ( BASE_URL )
39
- expect ( await api ( '/a' ) ) . toEqual ( [
40
- `${ BASE_URL } /a` ,
41
- {
42
- headers : {
43
- 'Content-Type' : 'application/json' ,
37
+ describe ( 'createRequest' , ( ) => {
38
+ it ( 'works' , async ( ) => {
39
+ const api = createRequest ( BASE_URL )
40
+ expect ( await api ( '/a' ) ) . toEqual ( [
41
+ new URL ( `${ BASE_URL } /a` ) ,
42
+ {
43
+ headers : {
44
+ 'Content-Type' : 'application/json' ,
45
+ } ,
46
+ } ,
47
+ ] )
48
+ } )
49
+
50
+ it ( 'path traversal attack' , async ( ) => {
51
+ const api = createRequest ( BASE_URL )
52
+ expect ( await api ( '/../a' ) ) . toEqual ( [
53
+ new URL ( `${ BASE_URL } /a` ) ,
54
+ {
55
+ headers : {
56
+ 'Content-Type' : 'application/json' ,
57
+ } ,
44
58
} ,
45
- } ,
46
- ] )
59
+ ] )
60
+ } )
47
61
} )
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ export function createRequest(baseUrl: string) {
37
37
) {
38
38
const newInput =
39
39
typeof input === 'string' && input . startsWith ( '/' )
40
- ? ` ${ baseUrl } ${ input } `
40
+ ? new URL ( input , baseUrl )
41
41
: input
42
42
return request ( newInput , options )
43
43
}
You can’t perform that action at this time.
0 commit comments