-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
Improved secure mode warnings #1609
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,7 +396,18 @@ if (!args.projectName) { | |
args.projectName = basename(resolve(filePath)); | ||
} | ||
} | ||
|
||
if ( | ||
filePath.includes(" ") || | ||
filePath.includes("\r") || | ||
filePath.includes("\n") | ||
) { | ||
console.log( | ||
`'${filePath}' contains spaces. This could lead to bugs when invoking external build tools.`, | ||
); | ||
if (isSecureMode) { | ||
process.exit(1); | ||
} | ||
} | ||
// Support for obom/cbom aliases | ||
if (process.argv[1].includes("obom") && !args.type) { | ||
args.type = "os"; | ||
|
@@ -411,6 +422,10 @@ const options = Object.assign({}, args, { | |
noBabel: args.noBabel || args.babel === false, | ||
project: args.projectId, | ||
deep: args.deep || args.evidence, | ||
output: | ||
isSecureMode && args.output === "bom.json" | ||
? resolve(join(filePath, args.output)) | ||
: args.output, | ||
}); | ||
|
||
if (process.argv[1].includes("cbom")) { | ||
|
@@ -419,6 +434,13 @@ if (process.argv[1].includes("cbom")) { | |
options.specVersion = 1.6; | ||
options.deep = true; | ||
} | ||
if (process.argv[1].includes("cdxgen-secure")) { | ||
console.log( | ||
"NOTE: Secure mode only restricts cdxgen from performing certain activities such as package installation. It does not provide security guarantees in the presence of malicious code.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we this message is enough. Should we use a different word instead of secure? |
||
); | ||
options.installDeps = false; | ||
process.env.CDXGEN_SECURE_MODE = true; | ||
} | ||
if (options.standard) { | ||
options.specVersion = 1.6; | ||
} | ||
|
@@ -542,10 +564,33 @@ applyAdvancedOptions(options); | |
* @returns | ||
*/ | ||
const checkPermissions = (filePath, options) => { | ||
const fullFilePath = resolve(filePath); | ||
if ( | ||
process.getuid && | ||
process.getuid() === 0 && | ||
process.env?.CDXGEN_IN_CONTAINER !== "true" | ||
) { | ||
console.log( | ||
"\x1b[1;35mSECURE MODE: DO NOT run cdxgen with root privileges.\x1b[0m", | ||
); | ||
} | ||
if (!process.permission) { | ||
if (isSecureMode) { | ||
console.log( | ||
"\x1b[1;35mSecure mode requires permission-related arguments. These can be passed as CLI arguments directly to the node runtime or set the NODE_OPTIONS environment variable as shown below.\x1b[0m", | ||
); | ||
const nodeOptionsVal = `--permission --allow-fs-read="${getTmpDir()}/*" --allow-fs-write="${getTmpDir()}/*" --allow-fs-read="${fullFilePath}/*" --allow-fs-write="${options.output}" --allow-child-process`; | ||
console.log( | ||
`${isWin ? "$env:" : "export "}NODE_OPTIONS='${nodeOptionsVal}'`, | ||
); | ||
if (process.env?.CDXGEN_IN_CONTAINER !== "true") { | ||
console.log( | ||
"TIP: Run cdxgen using the secure container image 'ghcr.io/cyclonedx/cdxgen-secure' for best experience.", | ||
); | ||
} | ||
} | ||
return true; | ||
} | ||
const fullFilePath = resolve(filePath); | ||
// Secure mode checks | ||
if (isSecureMode) { | ||
if (process.permission.has("fs.read", "*")) { | ||
|
@@ -565,7 +610,7 @@ const checkPermissions = (filePath, options) => { | |
} | ||
if (filePath !== fullFilePath) { | ||
console.log( | ||
`\x1b[1;35mSECURE MODE: Invoke cdxgen with an absolute path to improve security. Use ${fullFilePath} instead of ${filePath}.\x1b[0m`, | ||
`\x1b[1;35mSECURE MODE: Invoke cdxgen with an absolute path to improve security. Use '${fullFilePath}' instead of '${filePath}'\x1b[0m`, | ||
); | ||
if (fullFilePath.includes(" ")) { | ||
console.log( | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do this always or only in secure mode. Currently, the
bom.json
will be created in the current working directory.