-
Notifications
You must be signed in to change notification settings - Fork 6
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
Maven local #127
Maven local #127
Conversation
`.trim(); | ||
|
||
const DEFAULT_LOCAL_REPO = String( | ||
execSync(`mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout -f ${EMPTY_POM_XML_PATH}`, [], { |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
installMvnw: () => { | ||
console.info(`[maven-config-setup-helper] Installing mvnw...`); | ||
console.time(`[maven-config-setup-helper] Installing mvnw...`); | ||
execSync(`mvn -e org.apache.maven.plugins:maven-wrapper-plugin:${MVNW_VERSION}:wrapper ${BOOTSTRAP_CLI_ARGS}`, { |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
* @param tail A list of paths representing additional Maven repository directories, to be concatenated the default one (I.e, `maven.repo.local`) | ||
* */ | ||
prepareM2FromTail: (tmpM2Dir, tail) => { | ||
const resolvedTmpM2Dir = path.resolve(tmpM2Dir); |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
This path concatenation which depends on
library input
shell command
fs.mkdirSync(resolvedTmpM2Dir); | ||
|
||
// head | ||
execSync(`cp -nal ${DEFAULT_LOCAL_REPO}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" }); |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
fs.mkdirSync(resolvedTmpM2Dir); | ||
|
||
// head | ||
execSync(`cp -nal ${DEFAULT_LOCAL_REPO}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" }); |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
|
||
// tail | ||
for (const t of tail) { | ||
execSync(`cp -nal ${path.resolve(t)}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" }); |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
This shell command depends on an uncontrolled
absolute path
|
||
// tail | ||
for (const t of tail) { | ||
execSync(`cp -nal ${path.resolve(t)}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" }); |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we should avoid directly embedding user-controlled input into shell commands. Instead, we can use the child_process.execFile
function, which allows us to pass arguments as an array, thus avoiding shell interpretation. For cases where we need to use shell features like wildcards, we can use the shell-quote
library to safely escape the input.
- Replace the
execSync
calls withexecFileSync
where possible. - For commands that require shell interpretation, use the
shell-quote
library to escape the input.
-
Copy modified line R1 -
Copy modified line R20 -
Copy modified line R41 -
Copy modified line R102 -
Copy modified line R106
@@ -1,4 +1,4 @@ | ||
const shellQuote = require("shell-quote"); | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
@@ -19,3 +19,3 @@ | ||
|
||
const { execSync } = require("child_process"); | ||
const { execSync, execFileSync } = require("child_process"); | ||
const fs = require("fs"); | ||
@@ -40,3 +40,3 @@ | ||
const DEFAULT_LOCAL_REPO = String( | ||
execSync(`mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout -f ${EMPTY_POM_XML_PATH}`, [], { | ||
execFileSync("mvn", ["help:evaluate", "-Dexpression=settings.localRepository", "-q", "-DforceStdout", "-f", EMPTY_POM_XML_PATH], { | ||
stdio: "pipe", | ||
@@ -101,3 +101,3 @@ | ||
// head | ||
execSync(`cp -nal ${DEFAULT_LOCAL_REPO}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" }); | ||
execFileSync("cp", ["-nal", `${DEFAULT_LOCAL_REPO}/*`, resolvedTmpM2Dir], { stdio: "inherit" }); | ||
|
||
@@ -105,3 +105,3 @@ | ||
for (const t of tail) { | ||
execSync(`cp -nal ${path.resolve(t)}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" }); | ||
execFileSync("cp", ["-nal", `${path.resolve(t)}/*`, resolvedTmpM2Dir], { stdio: "inherit" }); | ||
} |
-
Copy modified lines R20-R23
@@ -19,3 +19,6 @@ | ||
"scripts": {}, | ||
"devDependencies": {} | ||
"devDependencies": {}, | ||
"dependencies": { | ||
"shell-quote": "^1.8.1" | ||
} | ||
} |
Package | Version | Security advisories |
shell-quote (npm) | 1.8.1 | None |
console.info(`[maven-config-setup-helper] Setting property '${key}' with value '${value}'...`); | ||
console.time(`[maven-config-setup-helper] Setting property '${key}' with value '${value}'...`); | ||
|
||
const cmd = `mvn versions:set-property -Dproperty=${key} -DnewVersion=${value} -DgenerateBackupPoms=false ${BOOTSTRAP_CLI_ARGS}`; |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
This string concatenation which depends on
library input
shell command
Copilot Autofix AI 3 months ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
stdio: "inherit", | ||
shell: "powershell.exe", | ||
}); | ||
execSync(cmd.replaceAll(" -", " `-"), { stdio: "inherit", shell: "powershell.exe" }); |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
execSync(`mvn versions:set-property -Dproperty=${key} -DnewVersion=${value} -DgenerateBackupPoms=false`, { | ||
stdio: "inherit", | ||
}); | ||
execSync(cmd, { stdio: "inherit" }); |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
56d19c5
to
fae5663
Compare
WIP