File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed
fileServices/MdPageServices Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 77} = require ( "@utils/markdown-utils" )
88const { slugifyCollectionName } = require ( "@utils/utils" )
99
10+ const { isSafePath } = require ( "@root/validators/validators" )
11+
1012const INDEX_FILE_NAME = "index.html"
1113
1214class ResourceDirectoryService {
@@ -79,7 +81,13 @@ class ResourceDirectoryService {
7981 sessionData ,
8082 { resourceRoomName, resourceCategoryName }
8183 ) {
82- if ( / [ ^ a - z A - Z 0 - 9 - ] / g. test ( resourceCategoryName ) ) {
84+ if (
85+ / [ ^ a - z A - Z 0 - 9 - ] / g. test ( resourceCategoryName ) ||
86+ ! isSafePath (
87+ `/${ resourceRoomName } /${ resourceCategoryName } ` ,
88+ `/${ resourceRoomName } `
89+ )
90+ ) {
8391 // Contains non-allowed characters
8492 throw new BadRequestError (
8593 "Special characters not allowed in resource category name"
@@ -111,7 +119,13 @@ class ResourceDirectoryService {
111119 githubSessionData ,
112120 { resourceRoomName, resourceCategoryName, newDirectoryName }
113121 ) {
114- if ( / [ ^ a - z A - Z 0 - 9 - ] / g. test ( newDirectoryName ) ) {
122+ if (
123+ / [ ^ a - z A - Z 0 - 9 - ] / g. test ( newDirectoryName ) ||
124+ ! isSafePath (
125+ `/${ resourceRoomName } /${ newDirectoryName } ` ,
126+ `/${ resourceRoomName } `
127+ )
128+ ) {
115129 // Contains non-allowed characters
116130 throw new BadRequestError (
117131 "Special characters not allowed in resource category name"
Original file line number Diff line number Diff line change 55 convertDataToMarkdown,
66} = require ( "@utils/markdown-utils" )
77
8- const { hasSpecialCharInTitle, isDateValid } = require ( "@validators/validators" )
8+ const {
9+ hasSpecialCharInTitle,
10+ isDateValid,
11+ isSafePath,
12+ } = require ( "@validators/validators" )
913
1014class ResourcePageService {
1115 constructor ( { gitHubService } ) {
@@ -16,7 +20,7 @@ class ResourcePageService {
1620 const fileNameArray = fileName . split ( ".md" ) [ 0 ]
1721 const tokenArray = fileNameArray . split ( "-" )
1822 const date = tokenArray . slice ( 0 , 3 ) . join ( "-" )
19- if ( ! isDateValid ( date ) )
23+ if ( ! isDateValid ( date ) || ! isSafePath ( `/ ${ fileName } ` , "/" ) )
2024 throw new BadRequestError ( "Special characters not allowed in file name" )
2125
2226 const type = [ "file" , "post" , "link" ] . includes ( tokenArray [ 3 ] )
Original file line number Diff line number Diff line change 66} = require ( "@utils/markdown-utils" )
77const { deslugifyCollectionName } = require ( "@utils/utils" )
88
9- const { hasSpecialCharInTitle } = require ( "@validators/validators" )
9+ const { hasSpecialCharInTitle, isSafePath } = require ( "@validators/validators" )
1010
1111class SubcollectionPageService {
1212 constructor ( { gitHubService, collectionYmlService } ) {
@@ -27,7 +27,11 @@ class SubcollectionPageService {
2727 ) {
2828 if (
2929 ! shouldIgnoreCheck &&
30- hasSpecialCharInTitle ( { title : fileName , isFile : true } )
30+ ( hasSpecialCharInTitle ( { title : fileName , isFile : true } ) ||
31+ ! isSafePath (
32+ `/${ collectionName } /${ subcollectionName } /${ fileName } ` ,
33+ `/${ collectionName } `
34+ ) )
3135 )
3236 throw new BadRequestError (
3337 `Special characters not allowed when creating files. Given name: ${ fileName } `
@@ -117,7 +121,13 @@ class SubcollectionPageService {
117121 sha,
118122 }
119123 ) {
120- if ( hasSpecialCharInTitle ( { title : newFileName , isFile : true } ) )
124+ if (
125+ hasSpecialCharInTitle ( { title : newFileName , isFile : true } ) ||
126+ ! isSafePath (
127+ `/${ collectionName } /${ subcollectionName } /${ newFileName } ` ,
128+ `/${ collectionName } `
129+ )
130+ )
121131 throw new BadRequestError (
122132 `Special characters not allowed when renaming files. Given name: ${ newFileName } `
123133 )
You can’t perform that action at this time.
0 commit comments