diff --git a/.gitignore b/.gitignore index cef656d62..58713cdb4 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ !/assets/fleet/ !/bin/ !/docs/ +!/docs/commands/ +!/docs/commands/** !/docs/dynamic-sbom-inference-settings.md !/patches/ !/scripts/ diff --git a/README.md b/README.md index 5b5e47e27..4d4e8b049 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,19 @@ socket --help ### Commands +See the [Command reference](docs/commands/README.md) for usage guides. + - `socket npm [args...]` and `socket npx [args...]` - Wraps npm/npx with Socket security scanning - `socket fix` - Fix CVEs in dependencies -- `socket optimize` - Optimize dependencies with [`@socketregistry`](https://github.com/SocketDev/socket-registry) overrides +- `socket organization dependencies` (alias: `socket org deps`) - List dependencies recorded for your organization - `socket cdxgen [command]` - Run [cdxgen](https://cyclonedx.github.io/cdxgen/#/?id=getting-started) for SBOM generation -- `socket patch ` - Apply, manage, and rollback Socket security patches for vulnerable dependencies +- `socket patch` - Scan for, apply, and manage Socket security patches for vulnerable dependencies + +- `socket optimize` - Optimize dependencies with [`@socketregistry`](https://github.com/SocketDev/socket-registry) overrides #### Patch subcommands diff --git a/docs/commands/README.md b/docs/commands/README.md new file mode 100644 index 000000000..4c9e0bd76 --- /dev/null +++ b/docs/commands/README.md @@ -0,0 +1,23 @@ +# Command reference + +Guides for Socket CLI commands: + +- [npm](npm.md) +- [npx](npx.md) +- [fix](fix.md) +- [optimize](optimize.md) +- [Organization dependencies](organization-dependencies.md) +- [cdxgen](cdxgen.md) +- [patch](patch/README.md) +- [ci](ci.md) + +Patch subcommands: + +- [scan](patch/scan.md) +- [get](patch/get.md) +- [apply](patch/apply.md) +- [rollback](patch/rollback.md) +- [list](patch/list.md) +- [remove](patch/remove.md) +- [setup](patch/setup.md) +- [repair](patch/repair.md) diff --git a/docs/commands/cdxgen.md b/docs/commands/cdxgen.md new file mode 100644 index 000000000..044131ddb --- /dev/null +++ b/docs/commands/cdxgen.md @@ -0,0 +1,16 @@ +# `socket cdxgen` + +With the npm-installed Socket CLI, generate a CycloneDX software bill of +materials (SBOM) for the current project. + +```sh +socket cdxgen --output socket-cdx.json +``` + +The default lifecycle is `pre-build`, which reads dependency metadata +without running project installs. Run `socket cdxgen --help` for cdxgen +options, including `--type` to select a project type. + +Standalone binaries have a separate set of capabilities. They can display +local cdxgen help even when SBOM generation is disabled in the build. +Use the npm-installed CLI to run the example above. diff --git a/docs/commands/ci.md b/docs/commands/ci.md new file mode 100644 index 000000000..dfbb70ea7 --- /dev/null +++ b/docs/commands/ci.md @@ -0,0 +1,12 @@ +# `socket ci` + +Run a security scan in CI. This alias for `socket scan create --report` +uses the default organization for your Socket API token and exits with a +nonzero status if the scan fails your security policy. + +```sh +socket ci +``` + +Use `--auto-manifest` to include locally generated manifests for supported +projects. Run `socket ci --help` for all options. diff --git a/docs/commands/fix.md b/docs/commands/fix.md new file mode 100644 index 000000000..a403c598f --- /dev/null +++ b/docs/commands/fix.md @@ -0,0 +1,38 @@ +# `socket fix` + +Find vulnerable dependencies and calculate upgrades for the current project. +The Socket API token needs the `fixes:list`, `full-scans:create`, and +`packages:list` permissions. + +In local mode, preview fixes or apply them to your working directory. + +```sh +# Preview fixes for all vulnerabilities +socket fix --all --no-apply-fixes + +# Apply fixes for all vulnerabilities +socket fix --all + +# Apply a fix for a specific vulnerability in another directory +socket fix ./path/to/project --id CVE-2021-23337 +``` + +`--no-apply-fixes` only affects local mode. Use either `--all` or `--id`. The +`--id` flag accepts CVE IDs, GHSA IDs, or package URLs (PURLs). A bare +`socket fix` still processes all vulnerabilities in local mode and prints a +deprecation warning. + +To open GitHub pull requests from CI, set these variables. + +- `CI` +- `SOCKET_CLI_GITHUB_TOKEN` or `GITHUB_TOKEN` +- `SOCKET_CLI_GIT_USER_NAME` +- `SOCKET_CLI_GIT_USER_EMAIL` + +The command also needs to resolve the repository from `GITHUB_REPOSITORY` or +the Git remote named `origin`. If any of the listed CI variables are missing, +the command runs in local mode. Use `--autopilot` to enable auto-merge for +pull requests the command opens. + +Run `socket fix --help` for options to filter ecosystems and package managers, +limit version changes, or choose how version ranges are updated. diff --git a/docs/commands/npm.md b/docs/commands/npm.md new file mode 100644 index 000000000..78d0f5196 --- /dev/null +++ b/docs/commands/npm.md @@ -0,0 +1,18 @@ +# `socket npm` + +Run npm through Socket's package security checks. + +```sh +socket npm install +socket npm exec cowsay +``` + +`--help` shows the wrapper help. `--dry-run` exits before running npm. The +wrapper filters out Socket flags but forwards `--json` to npm. + +The wrapper can use Socket's default public API token. A custom token needs +the `packages:list` permission. + +Run `socket wrapper on` to add both `npm` and `npx` aliases to a supported Bash +or Zsh startup file. Open a new terminal or run the `source` command printed +by Socket to activate the aliases in your current shell. diff --git a/docs/commands/npx.md b/docs/commands/npx.md new file mode 100644 index 000000000..d6c50ba2f --- /dev/null +++ b/docs/commands/npx.md @@ -0,0 +1,17 @@ +# `socket npx` + +Run npx through Socket's package security checks. + +```sh +socket npx cowsay +socket npx cowsay@1.6.0 hello +``` + +`--help` shows the wrapper help. `--dry-run` exits before running npx. + +The wrapper can use Socket's default public API token. A custom token needs +the `packages:list` permission. + +Run `socket wrapper on` to add both `npm` and `npx` aliases to a supported Bash +or Zsh startup file. Open a new terminal or run the `source` command printed +by Socket to activate the aliases in your current shell. diff --git a/docs/commands/optimize.md b/docs/commands/optimize.md new file mode 100644 index 000000000..da53723d5 --- /dev/null +++ b/docs/commands/optimize.md @@ -0,0 +1,15 @@ +# `socket optimize` + +Add or update `@socketregistry` package overrides in the current project. The +command requires a valid `package.json` and a nonempty lockfile. It updates +the lockfile when needed. + +```sh +socket optimize +socket optimize ./path/to/project --pin +``` + +By default, overrides apply to production and development dependencies. Use +`--prod` to limit them to production dependencies on supported package +managers. Bun and Yarn Berry do not support `--prod`. Use `--pin` to pin +overrides to the latest version. diff --git a/docs/commands/organization-dependencies.md b/docs/commands/organization-dependencies.md new file mode 100644 index 000000000..bd9acbb7d --- /dev/null +++ b/docs/commands/organization-dependencies.md @@ -0,0 +1,26 @@ +# Organization dependencies + +`socket organization dependencies` lists dependencies recorded for your +organization. You can also use `socket org deps` or `socket deps`. + +`--limit` sets the maximum number of dependencies returned and defaults to +50. Use `--offset` to skip dependencies. + +```sh +socket org deps +socket org deps --limit 20 --offset 10 --json +``` + +With `--json`, dependency rows are in `data.rows`. A `data.end` value of +`true` indicates there are no more results. + +Use `--purls` to filter by package URL (PURL). Separate PURLs with commas or +repeat the flag to search for multiple packages. The `pkg:` prefix is optional. + +```sh +socket org deps --purls 'npm/minimist@0.0.4,pkg:pypi/requests' +``` + +Include a version to match that version or omit it to match all indexed +versions. Partial matches, wildcards, version ranges, qualifiers, and +subpaths are unsupported. diff --git a/docs/commands/patch/README.md b/docs/commands/patch/README.md new file mode 100644 index 000000000..60f760cc5 --- /dev/null +++ b/docs/commands/patch/README.md @@ -0,0 +1,14 @@ +# `socket patch` + +Manage Socket security patches for dependencies. Patch records are stored in +`.socket/manifest.json` by default. + +```sh +socket patch scan +socket patch get --org --save-only +socket patch apply +``` + +See the guides for [scanning](scan.md), [downloading](get.md), [applying](apply.md), +[rolling back](rollback.md), [listing](list.md), [removing](remove.md), +[postinstall setup](setup.md), and [repairing the patch cache](repair.md). diff --git a/docs/commands/patch/apply.md b/docs/commands/patch/apply.md new file mode 100644 index 000000000..ce093f61c --- /dev/null +++ b/docs/commands/patch/apply.md @@ -0,0 +1,12 @@ +# `socket patch apply` + +Apply patches recorded in the project manifest. The default manifest is +`.socket/manifest.json`: + +```sh +socket patch apply +``` + +Use `--dry-run` to verify that patches can be applied without changing files. +Run `socket patch apply --help` for offline, global-package, and output +options. diff --git a/docs/commands/patch/get.md b/docs/commands/patch/get.md new file mode 100644 index 000000000..4da92098f --- /dev/null +++ b/docs/commands/patch/get.md @@ -0,0 +1,12 @@ +# `socket patch get` + +Download a security patch by UUID, CVE, GHSA, PURL, or package name. By +default, the command downloads and applies the selected patch: + +```sh +socket patch get --org +``` + +Use `--save-only` to download without applying. Use `--one-off` to apply a +patch immediately without saving it in `.socket/`. +Run `socket patch get --help` for identifier and confirmation options. diff --git a/docs/commands/patch/list.md b/docs/commands/patch/list.md new file mode 100644 index 000000000..977124396 --- /dev/null +++ b/docs/commands/patch/list.md @@ -0,0 +1,11 @@ +# `socket patch list` + +List patches recorded in the project manifest: + +```sh +socket patch list +socket patch list --json +``` + +Use `--cwd` to select a project directory or `--manifest-path` to select a +different manifest. Run `socket patch list --help` for all options. diff --git a/docs/commands/patch/remove.md b/docs/commands/patch/remove.md new file mode 100644 index 000000000..c1780d052 --- /dev/null +++ b/docs/commands/patch/remove.md @@ -0,0 +1,12 @@ +# `socket patch remove` + +Remove a patch by PURL or patch UUID. The command rolls back the patch's file +changes before removing its manifest entry: + +```sh +socket patch remove +``` + +Use `--skip-rollback` to remove only the manifest entry and leave the +installed files as they are. Run `socket patch remove --help` for confirmation +and global-package options. diff --git a/docs/commands/patch/repair.md b/docs/commands/patch/repair.md new file mode 100644 index 000000000..07ced38c8 --- /dev/null +++ b/docs/commands/patch/repair.md @@ -0,0 +1,12 @@ +# `socket patch repair` + +Download missing patch blobs into the local cache and remove unused blobs +from that cache. Repair only changes the patch cache. + +```sh +socket patch repair +``` + +Use `--dry-run` to preview changes, `--download-only` to skip cleanup, or +`--offline` to clean up without network access. +Run `socket patch repair --help` for all options. diff --git a/docs/commands/patch/rollback.md b/docs/commands/patch/rollback.md new file mode 100644 index 000000000..6ab1fb82e --- /dev/null +++ b/docs/commands/patch/rollback.md @@ -0,0 +1,12 @@ +# `socket patch rollback` + +Restore files changed by patches: + +```sh +socket patch rollback +socket patch rollback +``` + +Without an identifier, the command rolls back all patches in the manifest. Use +`--dry-run` to verify the rollback without changing files. Run +`socket patch rollback --help` for one-off and global-package options. diff --git a/docs/commands/patch/scan.md b/docs/commands/patch/scan.md new file mode 100644 index 000000000..cda006875 --- /dev/null +++ b/docs/commands/patch/scan.md @@ -0,0 +1,12 @@ +# `socket patch scan` + +Find available Socket security patches for installed packages in the current +project: + +```sh +socket patch scan +``` + +Use `--cwd` to choose a project directory, `--global` to scan globally +installed npm packages, or `--ecosystems` to restrict the scan. Use `--json` +for machine-readable output. Run `socket patch scan --help` for all options. diff --git a/docs/commands/patch/setup.md b/docs/commands/patch/setup.md new file mode 100644 index 000000000..9de2c884e --- /dev/null +++ b/docs/commands/patch/setup.md @@ -0,0 +1,13 @@ +# `socket patch setup` + +Configure patches to reapply after package installs. For npm projects, setup +prepends `socket patch apply --silent --ecosystems npm` to `postinstall` +scripts and can update nested `package.json` files. + +```sh +socket patch setup --dry-run +socket patch setup +``` + +Use `--dry-run` to preview the changes or `--yes` to skip the confirmation +prompt. Run `socket patch setup --help` for all options.