Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed semgrep issue #36

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const getBaseDir = ({baseDir}) => {
}
contentDir = baseDir
} else {
const appPath = join(__dirname, '..', '..', '..')
contentDir = join(appPath, baseDir)
const appPath = join(sanitizePath(__dirname), '..', '..', '..')
contentDir = join(sanitizePath(appPath), sanitizePath(baseDir))
if (!existsSync(contentDir)) {
sync(contentDir)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ export const getEntriesPath = (locale, contentTypeUid) => {
}
const config = getConfig().contentStore
const { contentDir } = getBaseDir(config)
const path = join(contentDir, buildPath(config.patterns.entries, data))
const path = join(sanitizePath(contentDir), sanitizePath(buildPath(config.patterns.entries, data)))
localePaths[locale][contentTypeUid] = path

return path
Expand Down Expand Up @@ -130,7 +130,7 @@ export const getAssetsPath = (locale) => {
}
const config = getConfig().contentStore
const { contentDir } = getBaseDir(config)
const path = join(contentDir, buildPath(config.patterns.assets, data))
const path = join(sanitizePath(contentDir), sanitizePath(buildPath(config.patterns.assets, data)))
// tslint:disable-next-line: no-string-literal
localePaths[locale]['_assets'] = path

Expand Down Expand Up @@ -158,7 +158,7 @@ export const getContentTypesPath = (locale) => {
}
const config = getConfig().contentStore
const { contentDir } = getBaseDir(config)
const path = join(contentDir, buildPath(config.patterns.content_types, data))
const path = join(sanitizePath(contentDir), sanitizePath(buildPath(config.patterns.content_types, data)))
// tslint:disable-next-line: no-string-literal
localePaths[locale]['_content_types'] = path

Expand Down Expand Up @@ -203,3 +203,7 @@ export const doNothingClause = function() {

return false
}

// To remove the relative path
export const sanitizePath = (str: string) =>
str?.replace(/^(\.\.(\/|\\|$))+/, "");
Loading