npx-ray 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +365 -0
- package/data/popular-packages.json +619 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +261 -0
- package/dist/cli.js.map +1 -0
- package/dist/diff.d.ts +21 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +301 -0
- package/dist/diff.js.map +1 -0
- package/dist/extract.d.ts +18 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +80 -0
- package/dist/extract.js.map +1 -0
- package/dist/github.d.ts +38 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +132 -0
- package/dist/github.js.map +1 -0
- package/dist/mcp.d.ts +19 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +219 -0
- package/dist/mcp.js.map +1 -0
- package/dist/registry.d.ts +19 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +229 -0
- package/dist/registry.js.map +1 -0
- package/dist/reporter.d.ts +23 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +208 -0
- package/dist/reporter.js.map +1 -0
- package/dist/scanners/binaries.d.ts +12 -0
- package/dist/scanners/binaries.d.ts.map +1 -0
- package/dist/scanners/binaries.js +80 -0
- package/dist/scanners/binaries.js.map +1 -0
- package/dist/scanners/dependencies.d.ts +14 -0
- package/dist/scanners/dependencies.d.ts.map +1 -0
- package/dist/scanners/dependencies.js +114 -0
- package/dist/scanners/dependencies.js.map +1 -0
- package/dist/scanners/hooks.d.ts +12 -0
- package/dist/scanners/hooks.d.ts.map +1 -0
- package/dist/scanners/hooks.js +126 -0
- package/dist/scanners/hooks.js.map +1 -0
- package/dist/scanners/ioc.d.ts +17 -0
- package/dist/scanners/ioc.d.ts.map +1 -0
- package/dist/scanners/ioc.js +414 -0
- package/dist/scanners/ioc.js.map +1 -0
- package/dist/scanners/obfuscation.d.ts +12 -0
- package/dist/scanners/obfuscation.d.ts.map +1 -0
- package/dist/scanners/obfuscation.js +227 -0
- package/dist/scanners/obfuscation.js.map +1 -0
- package/dist/scanners/secrets.d.ts +12 -0
- package/dist/scanners/secrets.d.ts.map +1 -0
- package/dist/scanners/secrets.js +173 -0
- package/dist/scanners/secrets.js.map +1 -0
- package/dist/scanners/static.d.ts +13 -0
- package/dist/scanners/static.d.ts.map +1 -0
- package/dist/scanners/static.js +138 -0
- package/dist/scanners/static.js.map +1 -0
- package/dist/scanners/typosquatting.d.ts +13 -0
- package/dist/scanners/typosquatting.d.ts.map +1 -0
- package/dist/scanners/typosquatting.js +102 -0
- package/dist/scanners/typosquatting.js.map +1 -0
- package/dist/scorer.d.ts +28 -0
- package/dist/scorer.d.ts.map +1 -0
- package/dist/scorer.js +139 -0
- package/dist/scorer.js.map +1 -0
- package/dist/types.d.ts +155 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# npx-ray
|
|
2
|
+
|
|
3
|
+
**X-ray vision for npm packages.**
|
|
4
|
+
|
|
5
|
+
A security scanner that audits source code, detects obfuscation, and flags supply chain risks -- all before you install. Downloads the tarball, runs 8 scanners in parallel, checks GitHub health, diffs source against the published package, and gives you a 0-100 risk score. No account required. Runs entirely locally.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/txdadlab/npx-ray/blob/main/LICENSE)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx npx-ray chalk # Scan any package
|
|
16
|
+
npx npx-ray chalk@5.0.0 # Scan specific version
|
|
17
|
+
npx npx-ray --json chalk # JSON output for CI/CD
|
|
18
|
+
npx npx-ray --mcp # Scan your MCP servers
|
|
19
|
+
npx npx-ray --verbose express # Detailed findings
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install globally:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install -g npx-ray
|
|
26
|
+
npx-ray lodash
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Transparency: We Scanned Ourselves
|
|
32
|
+
|
|
33
|
+
We ran npx-ray against its own source code. The result: **45/100 (F) -- DANGER**. Here's why, and why that's expected.
|
|
34
|
+
|
|
35
|
+
npx-ray's scanners detect dangerous patterns like `eval()`, `child_process`, `exec()`, and `-----BEGIN PRIVATE KEY-----` by searching for those strings in source code. But npx-ray's own detection rules *contain those exact strings* as regex patterns. The scanner flags its own signatures:
|
|
36
|
+
|
|
37
|
+
| Scanner | Self-Flag | Why |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| Static Analysis | 10 critical, 20 warnings | `static.js` contains detection patterns for `eval()`, `exec()`, `spawn()`, etc. -- the scanner finds its own rules |
|
|
40
|
+
| Secrets | 1 critical | `secrets.js` contains the regex `-----BEGIN.*PRIVATE KEY-----` as a detection pattern -- flagged as a private key |
|
|
41
|
+
| Obfuscation | 2 warnings | `ioc.js` and `obfuscation.js` contain hex escape sequences used for pattern matching |
|
|
42
|
+
| IOC | 1 IP | `ioc.js` contains the example IP `1.2.3.4` in its test ignore list |
|
|
43
|
+
|
|
44
|
+
**This is the "who watches the watchmen" problem** -- any security tool that scans for dangerous patterns will inevitably contain those patterns in its own detection rules. This does not affect scanning of other packages. We publish this result for full transparency.
|
|
45
|
+
|
|
46
|
+
Full source code: [github.com/txdadlab/npx-ray](https://github.com/txdadlab/npx-ray)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Example Output
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
npx-ray v1.0.0 — X-ray vision for npm packages
|
|
54
|
+
───────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
Package: chalk@5.4.1
|
|
57
|
+
Publisher: sindresorhus
|
|
58
|
+
Published: 2024-11-21
|
|
59
|
+
License: MIT
|
|
60
|
+
Files: 7
|
|
61
|
+
Size: 11.2 KB
|
|
62
|
+
|
|
63
|
+
───────────────────────────────────────────────────────
|
|
64
|
+
Risk Score: 90/100 (A)
|
|
65
|
+
───────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
Scan Results
|
|
68
|
+
|
|
69
|
+
✅ Static: No dangerous patterns detected
|
|
70
|
+
✅ Obfuscation: No obfuscation detected
|
|
71
|
+
✅ Hooks: No lifecycle hooks found
|
|
72
|
+
✅ Secrets: No embedded secrets detected
|
|
73
|
+
✅ Binaries: No binary files found
|
|
74
|
+
✅ Dependencies: 0 direct, 0 optional dependencies
|
|
75
|
+
✅ Typosquatting: "chalk" is a known popular package
|
|
76
|
+
|
|
77
|
+
GitHub
|
|
78
|
+
✅ Repository: chalk/chalk
|
|
79
|
+
Stars: 22000 | Forks: 850 | Open Issues: 12
|
|
80
|
+
Created: 2013-07-18 | Last Push: 2024-11-21
|
|
81
|
+
|
|
82
|
+
Source Diff
|
|
83
|
+
✅ Source matches published package
|
|
84
|
+
|
|
85
|
+
───────────────────────────────────────────────────────
|
|
86
|
+
Verdict: CLEAN — No issues detected
|
|
87
|
+
───────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
Scan completed in 3.2s
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## What It Checks
|
|
95
|
+
|
|
96
|
+
| Scanner | What it detects | Severity |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| **Static Analysis** | `eval()`, `child_process`, `exec()`, `spawn()`, `fetch()`, dynamic `require()`, filesystem writes, `process.env` access | Critical / Warning / Info |
|
|
99
|
+
| **Obfuscation** | Shannon entropy anomalies, hex-encoded strings, base64 blobs (>500 chars), string array rotation (>50 elements), suspiciously long lines | Critical / Warning / Info |
|
|
100
|
+
| **Lifecycle Hooks** | `preinstall`, `postinstall`, and other install-time scripts; shell commands in hooks (`curl`, `wget`, `bash`, `node -e`) | Critical / Warning |
|
|
101
|
+
| **Secrets** | AWS keys, GitHub/npm tokens, private keys, credentials in URLs, generic API keys and tokens | Critical / Warning |
|
|
102
|
+
| **Binaries** | `.node`, `.so`, `.dll`, `.dylib`, `.exe`, `.bin`, `.wasm` files that cannot be source-reviewed | Warning |
|
|
103
|
+
| **Dependencies** | Dependency bloat (>20 warning, >50 critical), wildcard/unpinned versions (`*`, `latest`), git URL dependencies | Critical / Warning |
|
|
104
|
+
| **Typosquatting** | Package names within 1-2 edits of popular packages (Levenshtein distance) | Critical / Warning |
|
|
105
|
+
| **GitHub Health** | Stars, forks, archive status, repo age, publisher-vs-owner mismatch | Scoring adjustment |
|
|
106
|
+
| **Source Diff** | Files in npm but not in GitHub repo, content hash mismatches between published and source | Scoring adjustment |
|
|
107
|
+
| **IOC Extraction** | URLs and IP addresses extracted and defanged for safe review; decodes hex escapes, unicode escapes, `String.fromCharCode()`, and base64 | Warning (decoded) / Info (plaintext) |
|
|
108
|
+
| **MCP Servers** | Unpinned MCP server versions in editor configs, tool description injection risks | Via `--mcp` flag |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Limitations
|
|
113
|
+
|
|
114
|
+
npx-ray is a **static analysis** tool. It does not execute any code from scanned packages. This means there are classes of threats it cannot fully detect:
|
|
115
|
+
|
|
116
|
+
- **Cross-file obfuscation** -- A payload split across multiple files (e.g., encrypted blob in `data.js` with the decryption key in `utils.js`) cannot be reassembled by static analysis. The obfuscation scanner will flag the suspicious patterns, but the IOC scanner cannot extract the hidden URL.
|
|
117
|
+
- **Key-based encoding** -- XOR ciphers, custom lookup tables, or any encoding that requires a runtime key to decode. npx-ray can decode self-contained encodings (hex, unicode, base64, charCode) but not schemes that depend on external keys or functions.
|
|
118
|
+
- **Runtime string construction** -- Patterns like `arr[3] + arr[7] + arr[1]` where array elements are defined elsewhere, or template literals assembled from variables across scopes.
|
|
119
|
+
- **Multi-stage deobfuscation** -- Pipelines like base64 decode -> XOR -> URL, where the output of one decoding step feeds into another that requires context.
|
|
120
|
+
- **Novel or custom obfuscation** -- Obfuscation techniques not covered by the built-in pattern library. The entropy scanner provides a general safety net (obfuscated code tends to have high Shannon entropy), but purpose-built obfuscators can evade specific signature checks.
|
|
121
|
+
- **Native binary analysis** -- `.node`, `.so`, `.dll`, and `.wasm` files are flagged as unreviable but their contents are not analyzed.
|
|
122
|
+
|
|
123
|
+
**What this means in practice:** npx-ray catches the majority of real-world supply chain attacks, which overwhelmingly rely on plaintext or simple single-layer obfuscation. Sophisticated multi-file encrypted payloads exist but are rare in npm malware. When npx-ray encounters obfuscation it can't decode, the obfuscation scanner still flags the suspicious patterns -- you just won't see the decoded IOC.
|
|
124
|
+
|
|
125
|
+
For defense-in-depth, combine npx-ray with runtime monitoring, sandboxed installs, and lockfile auditing.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Risk Scoring
|
|
130
|
+
|
|
131
|
+
Every package receives a score from 0 (dangerous) to 100 (clean), computed by summing weighted category scores. Each category starts at its maximum points and deducts based on the severity of findings.
|
|
132
|
+
|
|
133
|
+
### Category Weights
|
|
134
|
+
|
|
135
|
+
| Category | Max Points | Critical Deduction | Warning Deduction | Info Deduction |
|
|
136
|
+
|---|---|---|---|---|
|
|
137
|
+
| Static Analysis | 25 | -15 | -5 | 0 |
|
|
138
|
+
| Obfuscation | 15 | -10 | -10 | -3 |
|
|
139
|
+
| Lifecycle Hooks | 10 | -10 | -5 | 0 |
|
|
140
|
+
| Dependencies | 10 | -10 | -5 | 0 |
|
|
141
|
+
| GitHub Health | 15 | -- | -- | -- |
|
|
142
|
+
| Source Diff | 10 | -- | -- | -- |
|
|
143
|
+
| Secrets | 5 | -5 | -5 | 0 |
|
|
144
|
+
| Binaries | 5 | -3 | -3 | -1 |
|
|
145
|
+
| Typosquatting | 5 | -5 | -5 | 0 |
|
|
146
|
+
| **Total** | **100** | | | |
|
|
147
|
+
|
|
148
|
+
GitHub Health deductions: archived repo (-10), zero stars (-5), repo less than 1 month old (-5), publisher does not match GitHub owner (-10).
|
|
149
|
+
|
|
150
|
+
Source Diff deductions: -5 per unexpected file in the npm package that is not in the GitHub repo.
|
|
151
|
+
|
|
152
|
+
### Letter Grades
|
|
153
|
+
|
|
154
|
+
| Grade | Score | Verdict | Exit Code |
|
|
155
|
+
|---|---|---|---|
|
|
156
|
+
| **A** | 90 -- 100 | CLEAN -- No issues detected | 0 |
|
|
157
|
+
| **B** | 80 -- 89 | CLEAN -- No issues detected | 0 |
|
|
158
|
+
| **C** | 70 -- 79 | CAUTION -- Review findings before installing | 1 |
|
|
159
|
+
| **D** | 60 -- 69 | DANGER -- Manual review strongly recommended | 2 |
|
|
160
|
+
| **F** | 0 -- 59 | DANGER -- Manual review strongly recommended | 2 |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## CLI Reference
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
Usage: npx-ray [options] [package]
|
|
168
|
+
|
|
169
|
+
X-ray vision for npm packages — security scanner that audits source code,
|
|
170
|
+
detects obfuscation, and flags supply chain risks before you install
|
|
171
|
+
|
|
172
|
+
Arguments:
|
|
173
|
+
package Package to scan (name, name@version, or local tarball)
|
|
174
|
+
|
|
175
|
+
Options:
|
|
176
|
+
--json Output results as JSON (for CI/CD pipelines)
|
|
177
|
+
--verbose Show detailed findings for each scanner
|
|
178
|
+
--mcp Scan MCP servers from editor configurations
|
|
179
|
+
--no-github Skip GitHub repository checks
|
|
180
|
+
--no-diff Skip source-vs-published diff
|
|
181
|
+
-V, --version Output the version number
|
|
182
|
+
-h, --help Display help
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Examples
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# Scan a package by name (resolves latest version)
|
|
189
|
+
npx npx-ray express
|
|
190
|
+
|
|
191
|
+
# Scan a specific version
|
|
192
|
+
npx npx-ray lodash@4.17.21
|
|
193
|
+
|
|
194
|
+
# JSON output for scripting or CI
|
|
195
|
+
npx npx-ray react --json
|
|
196
|
+
|
|
197
|
+
# Full detail with every individual finding
|
|
198
|
+
npx npx-ray axios --verbose
|
|
199
|
+
|
|
200
|
+
# Fast scan (skip GitHub API and source diff)
|
|
201
|
+
npx npx-ray leftpad --no-github --no-diff
|
|
202
|
+
|
|
203
|
+
# Scan all MCP servers configured on your machine
|
|
204
|
+
npx npx-ray --mcp
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## MCP Server Scanning
|
|
210
|
+
|
|
211
|
+
The `--mcp` flag scans your local editor configurations for MCP (Model Context Protocol) servers that use npm packages. It automatically discovers servers from:
|
|
212
|
+
|
|
213
|
+
- **Claude Desktop** (macOS, Windows, Linux)
|
|
214
|
+
- **Cursor** (`~/.cursor/mcp.json`)
|
|
215
|
+
- **VS Code** (`~/.vscode/mcp.json`)
|
|
216
|
+
- **Claude Code** (`~/.claude.json`)
|
|
217
|
+
- **Windsurf** (`~/.windsurf/mcp.json`, `~/.codeium/windsurf/mcp_config.json`)
|
|
218
|
+
|
|
219
|
+
For each npm-based MCP server found, npx-ray:
|
|
220
|
+
|
|
221
|
+
1. Checks whether the package version is **pinned** (e.g., `@anthropic-ai/mcp-server@1.2.3` vs unpinned `@anthropic-ai/mcp-server`)
|
|
222
|
+
2. Runs the **full security scan** on the npm package
|
|
223
|
+
3. Reports a summary across all servers
|
|
224
|
+
|
|
225
|
+
Unpinned MCP servers are a supply chain risk -- an attacker who compromises a package can push a new version that gets auto-installed the next time your editor launches.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
npx npx-ray --mcp
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## CI/CD Integration
|
|
234
|
+
|
|
235
|
+
Use npx-ray in your CI pipeline to gate new dependencies before they enter your project.
|
|
236
|
+
|
|
237
|
+
### GitHub Actions
|
|
238
|
+
|
|
239
|
+
```yaml
|
|
240
|
+
name: Dependency Security Scan
|
|
241
|
+
on:
|
|
242
|
+
pull_request:
|
|
243
|
+
paths:
|
|
244
|
+
- 'package.json'
|
|
245
|
+
- 'package-lock.json'
|
|
246
|
+
|
|
247
|
+
jobs:
|
|
248
|
+
scan:
|
|
249
|
+
runs-on: ubuntu-latest
|
|
250
|
+
strategy:
|
|
251
|
+
matrix:
|
|
252
|
+
package: [express, lodash, axios] # or parse from diff
|
|
253
|
+
steps:
|
|
254
|
+
- name: Security scan
|
|
255
|
+
run: npx npx-ray ${{ matrix.package }} --json
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Exit Codes
|
|
259
|
+
|
|
260
|
+
| Code | Meaning | Action |
|
|
261
|
+
|---|---|---|
|
|
262
|
+
| 0 | Grade A or B -- clean | Proceed |
|
|
263
|
+
| 1 | Grade C -- warnings found | Review findings |
|
|
264
|
+
| 2 | Grade D or F -- critical issues | Block and investigate |
|
|
265
|
+
|
|
266
|
+
### JSON Output Schema
|
|
267
|
+
|
|
268
|
+
The `--json` flag outputs a structured report that can be parsed by downstream tools:
|
|
269
|
+
|
|
270
|
+
```json
|
|
271
|
+
{
|
|
272
|
+
"package": {
|
|
273
|
+
"name": "example",
|
|
274
|
+
"version": "1.0.0",
|
|
275
|
+
"license": "MIT",
|
|
276
|
+
"publisher": "author",
|
|
277
|
+
"dependencies": {}
|
|
278
|
+
},
|
|
279
|
+
"scanners": [
|
|
280
|
+
{
|
|
281
|
+
"name": "static",
|
|
282
|
+
"passed": true,
|
|
283
|
+
"findings": [],
|
|
284
|
+
"summary": "No dangerous patterns detected"
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
"score": 95,
|
|
288
|
+
"grade": "A",
|
|
289
|
+
"verdict": "CLEAN — No issues detected",
|
|
290
|
+
"duration": 2100
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## How It Works
|
|
297
|
+
|
|
298
|
+
1. **Fetch metadata** from the npm registry (version, tarball URL, publisher, dependencies)
|
|
299
|
+
2. **Download and extract** the tarball to a temporary directory -- nothing is installed, no scripts run
|
|
300
|
+
3. **Run 8 scanners in parallel** against the extracted source code:
|
|
301
|
+
- Static analysis (dangerous API patterns)
|
|
302
|
+
- Obfuscation detection (entropy, hex, base64, string arrays)
|
|
303
|
+
- Lifecycle hooks (install scripts)
|
|
304
|
+
- Secrets (API keys, tokens, private keys)
|
|
305
|
+
- Binaries (non-reviewable native addons)
|
|
306
|
+
- Dependency analysis (bloat, wildcards, git URLs)
|
|
307
|
+
- Typosquatting (Levenshtein distance against top npm packages)
|
|
308
|
+
- IOC extraction (URLs and IPs, with deobfuscation layer)
|
|
309
|
+
4. **Check GitHub health** via the unauthenticated API (stars, age, archive status, publisher match)
|
|
310
|
+
5. **Diff source vs. published** by downloading the GitHub repo tarball and comparing file lists and content hashes
|
|
311
|
+
6. **Calculate score** using weighted category deductions
|
|
312
|
+
7. **Output report** (colored terminal output or JSON)
|
|
313
|
+
8. **Clean up** the temporary directory
|
|
314
|
+
|
|
315
|
+
No data is sent to any external service. GitHub API requests are unauthenticated and optional (skip with `--no-github`).
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Comparison
|
|
320
|
+
|
|
321
|
+
| Feature | npx-ray | npm audit | socket.dev | mcp-scan |
|
|
322
|
+
|---|---|---|---|---|
|
|
323
|
+
| Source code analysis | Yes | No | No | No |
|
|
324
|
+
| Obfuscation detection | Yes | No | Yes | No |
|
|
325
|
+
| Shannon entropy analysis | Yes | No | No | No |
|
|
326
|
+
| Typosquatting detection | Yes | No | Yes | No |
|
|
327
|
+
| Source-vs-npm diff | Yes | No | No | No |
|
|
328
|
+
| Lifecycle hook scanning | Yes | No | Yes | No |
|
|
329
|
+
| Secret detection | Yes | No | No | No |
|
|
330
|
+
| Binary file detection | Yes | No | No | No |
|
|
331
|
+
| Dependency analysis | Yes | Yes | Yes | No |
|
|
332
|
+
| GitHub health check | Yes | No | Yes | No |
|
|
333
|
+
| MCP server scanning | Yes | No | No | Yes |
|
|
334
|
+
| Works pre-install | Yes | No (post-install) | Yes | Yes |
|
|
335
|
+
| Runs locally | Yes | Yes | No (SaaS) | Yes |
|
|
336
|
+
| No account required | Yes | Yes | No | Yes |
|
|
337
|
+
| JSON output for CI | Yes | Yes | Yes | Yes |
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Contributing
|
|
342
|
+
|
|
343
|
+
Contributions are welcome. Please open an issue first to discuss what you would like to change.
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
git clone https://github.com/txdadlab/npx-ray.git
|
|
347
|
+
cd npx-ray
|
|
348
|
+
npm install
|
|
349
|
+
npm run build
|
|
350
|
+
node dist/cli.js chalk # Test your changes
|
|
351
|
+
npm test # Run the test suite
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Adding a New Scanner
|
|
355
|
+
|
|
356
|
+
1. Create `src/scanners/your-scanner.ts` implementing the `ScannerResult` interface
|
|
357
|
+
2. Import and add it to the `Promise.all` array in `src/cli.ts`
|
|
358
|
+
3. Add a weight entry in `src/scorer.ts` under `CATEGORY_WEIGHTS`
|
|
359
|
+
4. Add tests in `tests/`
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## License
|
|
364
|
+
|
|
365
|
+
[Apache-2.0](LICENSE)
|