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

Deduplicate file staging logic #740

Merged
merged 3 commits into from
Oct 25, 2023
Merged

Deduplicate file staging logic #740

merged 3 commits into from
Oct 25, 2023

Conversation

antonok-edm
Copy link
Collaborator

Incremental work towards #622.

This PR refactors duplicated logic across all packaging scripts to use common stageFiles and stageDir utilities, removing a net of almost 100 lines.

In the future I'd like to consolidate all components into using just one of these utilities, however I've left that for a followup as it requires deeper understanding of each component being packaged and cleanup of some legacy backwards-compatible code.

@@ -571,6 +572,45 @@ const escapeStringForJSON = str => {
return JSON.stringify(str).slice(1, -1)
}

const copyManifestWithVersion = (originalLocation, outputDir, version) => {
const outputLocation = path.join(outputDir, 'manifest.json')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Source: https://semgrep.dev/r/javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal


Cc @thypon @bcaller

copyManifestWithVersion(inputPath, outputDir, version)
hasManifest = true
} else {
fs.copyFileSync(inputPath, path.join(outputDir, outputName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Source: https://semgrep.dev/r/javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal


Cc @thypon @bcaller

replace.sync(replaceOptions)
util.stageDir(
undefined,
path.join(path.resolve(), 'build', 'ntp-sponsored-images', 'resources', locale, '/'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Source: https://semgrep.dev/r/javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal


Cc @thypon @bcaller

// Only copy resources.json into components with a UUID. We will migrate to
// ad-block components are already written in the output directory
// so we don't need to stage anything
const originalManifest = path.join(outputDir, 'manifest.json')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Source: https://semgrep.dev/r/javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal


Cc @thypon @bcaller

replace.sync(replaceOptions)
util.stageDir(
undefined,
path.join(path.resolve(), 'build', 'user-model-installer', 'resources', locale, '/'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Source: https://semgrep.dev/r/javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal


Cc @thypon @bcaller

replace.sync(replaceOptions)
util.stageDir(
undefined,
path.join(path.resolve(), 'build', 'ntp-super-referrer', 'resources', superReferrerName, '/'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Source: https://semgrep.dev/r/javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal


Cc @thypon @bcaller

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants