File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ const { isSafePath } = require ( "../utils/misc" )
2+
13export class PageService {
24 constructor ( { apiClient } ) {
35 this . apiClient = apiClient
@@ -12,6 +14,22 @@ export class PageService {
1214 resourceCategoryName,
1315 fileName,
1416 } ) {
17+ // Check the input parameters to ensure the paths are safe
18+ const paramsToCheck = [
19+ siteName ,
20+ collectionName ,
21+ subCollectionName ,
22+ resourceRoomName ,
23+ resourceCategoryName ,
24+ fileName ,
25+ ]
26+
27+ paramsToCheck . forEach ( ( param ) => {
28+ if ( param && ! isSafePath ( param ) ) {
29+ throw new Error ( `Unsafe path detected in parameter: ${ param } ` )
30+ }
31+ } )
32+
1533 let endpoint = `/sites/${ siteName } `
1634 if ( collectionName ) {
1735 endpoint += `/collections/${ collectionName } `
Original file line number Diff line number Diff line change @@ -7,3 +7,12 @@ export const isLinkInternal = (url: string) => {
77 tempLink . href = url
88 return tempLink . hostname === window . location . hostname
99}
10+
11+ // Util method to check if a URL path is safe
12+ export const isSafePath = ( path : string ) : boolean => {
13+ if ( path . indexOf ( "\\" ) !== - 1 ) {
14+ return false
15+ }
16+
17+ return true
18+ }
You can’t perform that action at this time.
0 commit comments