Skip to content

feat(probes): add unsafe-command #327

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

feat(probes): add unsafe-command #327

wants to merge 24 commits into from

Conversation

tony-go
Copy link
Member

@tony-go tony-go commented May 27, 2025

I would like to introduce unsafe-command probe.

I had the idea earlier in the day reading a book on macOS malware where authors try to detect if SIP is enabled (csrutil).

I noticed a bunch of commands that could be suspicious if passed in spawn/exec.

I imaged something where we could have a bunch of specific commands we could mark as suspicious.

My concerns is "What about false positives?" Maybe we would like to have a probe that could take a list of commands and add warnings only for these cases.

Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
@fraxken
Copy link
Member

fraxken commented May 27, 2025

I don't worry much about false positive (we could still see in the real world if there is a lot or not). And CLI settings still propose to disable them (I think I will push to make experimental warning disable by default).

@fraxken
Copy link
Member

fraxken commented May 27, 2025

Opened an issue in CLI: NodeSecure/cli#493

@fraxken fraxken mentioned this pull request Jun 2, 2025
tony-go added 4 commits June 10, 2025 08:30
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Copy link

changeset-bot bot commented Jun 10, 2025

⚠️ No Changeset found

Latest commit: 38224e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

tony-go added 3 commits June 12, 2025 21:49
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
@tony-go
Copy link
Member Author

tony-go commented Jun 13, 2025

Now let's update doc and readme

tony-go added 2 commits June 13, 2025 09:23
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
@tony-go tony-go marked this pull request as ready for review June 13, 2025 07:28
@tony-go tony-go requested a review from fraxken June 13, 2025 07:28
@fraxken fraxken requested a review from PierreDemailly June 13, 2025 09:39
@tony-go
Copy link
Member Author

tony-go commented Jun 13, 2025

@fraxken I propose a unsafe-command instead. WDYT? (that one would contain exec and spawn)

@fraxken
Copy link
Member

fraxken commented Jun 13, 2025

@fraxken I propose a unsafe-command instead. WDYT? (that one would contain exec and spawn)

Good for me

tony-go added 3 commits June 16, 2025 22:37
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
tony-go added 3 commits June 16, 2025 22:42
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
@tony-go
Copy link
Member Author

tony-go commented Jun 16, 2025

Now I'll add exec cases

Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
assert.equal(sastAnalysis.warnings().length, 0);
});

// Exec
Copy link
Member Author

Choose a reason for hiding this comment

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

You'll realised that I copy paste the same cases. we could add both APIs (exec and spawn) for each cases. I just started with the simplest one :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me just know what do you prefer @fraxken I have no strong opinion.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm if tests are the same then you can probably do a for loop?

Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
@tony-go tony-go changed the title feat(probes): add isUnsafeSpawn feat(probes): add unsafe-command Jun 16, 2025
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
and revert unrelated one

Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
@fraxken
Copy link
Member

fraxken commented Jun 17, 2025

Do we also want to detect for synchronous methods? (such as execSync and spawnSync).

@tony-go
Copy link
Member Author

tony-go commented Jun 17, 2025

Do we also want to detect for synchronous methods? (such as execSync and spawnSync).

yeah 🚀 that's a great idea

tony-go added 4 commits June 18, 2025 09:20
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
Signed-off-by: Tony Gorez <gorez.tony@gmail.com>
assert.equal(sastAnalysis.warnings().length, 0);
});

// Exec
Copy link
Member

Choose a reason for hiding this comment

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

Hmm if tests are the same then you can probably do a for loop?

return kUnsafeCommands.some((unsafeCommand) => command.includes(unsafeCommand));
}

function isSpwanOrExec(name) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function isSpwanOrExec(name) {
function isSpawnOrExec(name) {


let command = commandArg.value;
if (typeof command === "string" && isUnsafeCommand(command)) {
// Spwaned command arguments are filled into an Array
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Spwaned command arguments are filled into an Array
// Spawned command arguments are filled into an Array

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

Successfully merging this pull request may close these issues.

3 participants