safedeps 0.2.7__tar.gz

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.
@@ -0,0 +1,546 @@
1
+ Metadata-Version: 2.4
2
+ Name: safedeps
3
+ Version: 0.2.7
4
+ Summary: Cross-ecosystem dependency policy gate for safer installs and updates.
5
+ Author: Giovanni De Miccoli
6
+ License: MIT
7
+ Keywords: security,supply-chain,dependencies,sbom,audit,pip,npm,nuget
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Environment :: Console
10
+ Classifier: Topic :: Security
11
+ Classifier: Topic :: Software Development :: Build Tools
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: PyYAML>=6.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8.0; extra == "dev"
17
+
18
+ # SafeDeps
19
+
20
+ SafeDeps is a dependency safety gate.
21
+
22
+ It checks your project dependencies before install/update and can block risky changes (for example vulnerable, untrusted, or floating versions).
23
+
24
+ It works with Python, npm, NuGet, and Git dependency definitions.
25
+
26
+ You can use SafeDeps in two ways:
27
+
28
+ - Terminal/CLI mode (`safedeps scan`, `safedeps setup`, `safedeps help`, etc.)
29
+ - Web UI mode (recommended for guided usage)
30
+
31
+ Open the UI with:
32
+
33
+ ```bash
34
+ python -m safedeps.cli ui . --host 127.0.0.1 --port 8877 --open-browser
35
+ ```
36
+
37
+ Install from PyPI (recommended for standard usage):
38
+
39
+ ```bash
40
+ pip install safedeps
41
+ ```
42
+
43
+ > Status note (May 2026): PyPI publishing is now available.
44
+ > npm and NuGet publishing are still being finalized.
45
+
46
+ ## Start In 60 Seconds
47
+
48
+ 1. Get the repository (choose one option):
49
+
50
+ Option A - clone with Git:
51
+
52
+ ```bash
53
+ git clone https://github.com/jaydemks/SafeDeps.git
54
+ cd SafeDeps
55
+ ```
56
+
57
+ Option B - download ZIP from GitHub and extract it:
58
+
59
+ ```bash
60
+ cd /path/to/extracted/SafeDeps
61
+ ```
62
+
63
+ 2. Create and activate a virtual environment:
64
+
65
+ macOS/Linux:
66
+
67
+ ```bash
68
+ python3 -m venv .venv-test
69
+ source .venv-test/bin/activate
70
+ ```
71
+
72
+ Windows (PowerShell):
73
+
74
+ ```powershell
75
+ py -m venv .venv-test
76
+ .\.venv-test\Scripts\Activate.ps1
77
+ ```
78
+
79
+ If script execution is blocked in PowerShell:
80
+
81
+ ```powershell
82
+ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
83
+ .\.venv-test\Scripts\Activate.ps1
84
+ ```
85
+
86
+ 3. Install SafeDeps from the local repository folder:
87
+
88
+ ```bash
89
+ python -m pip install -e .[dev]
90
+ ```
91
+
92
+ 4. In your project folder, run one-time setup:
93
+
94
+ ```bash
95
+ safedeps setup .
96
+ source .safedeps/activate.sh
97
+ ```
98
+
99
+ Windows (PowerShell) setup + activation:
100
+
101
+ ```powershell
102
+ python -m safedeps.cli setup .
103
+ . .\.safedeps\activate.ps1
104
+ ```
105
+
106
+ 5. Open the UI (recommended command, works even if shell entrypoint is missing):
107
+
108
+ ```bash
109
+ python -m safedeps.cli ui . --host 127.0.0.1 --port 8877 --open-browser
110
+ ```
111
+
112
+ Then open `http://127.0.0.1:8877/`.
113
+
114
+ 6. Re-scan from UI or CLI:
115
+
116
+ ```bash
117
+ safedeps scan . --fail-on HIGH
118
+ ```
119
+
120
+ After activation, runtime dependency operations are guarded in the shell session.
121
+
122
+ ## What It Is (Simple)
123
+
124
+ SafeDeps is a guardrail you run before installing or updating dependencies.
125
+
126
+ It helps you block risky dependency changes early, for example:
127
+
128
+ - unpinned/floating versions
129
+ - untrusted registries/sources
130
+ - known vulnerable packages (from configured local intelligence/feed)
131
+ - missing lockfiles
132
+ - suspicious package patterns
133
+
134
+ In short: it is a backend safety gate for dependency workflows in local dev and CI.
135
+
136
+ UI full guide: `docs/UI_DOCUMENTATION.md`
137
+
138
+ ## Test Status (Current)
139
+
140
+ - Tested and validated now:
141
+ - Python CLI flow
142
+ - `pip` and `python -m pip` runtime guard behavior
143
+ - UI guard toggles and dynamic updates
144
+ - Still in active validation:
145
+ - npm runtime guard end-to-end
146
+ - NuGet/.NET runtime flows end-to-end
147
+
148
+ ## Current State
149
+
150
+ - Core engine: Python CLI/library (`safedeps` package)
151
+ - npm distribution: wrapper package present in `packages/npm-wrapper`
152
+ - .NET global tool wrapper: implemented in `packages/dotnet-tool`
153
+ - Publish status:
154
+ - PyPI: published (installable with `pip install safedeps`)
155
+ - npm: not published yet
156
+ - NuGet: not published yet
157
+ - Target: finalize npm/NuGet publishing after release validation checks pass
158
+ - Security outputs:
159
+ - `security-artifacts/safedeps-report.json`
160
+ - `security-artifacts/safedeps-sbom.json`
161
+
162
+ ## Versioning Policy
163
+
164
+ - Single public version for all official distributions.
165
+ - Python core package version in `pyproject.toml` must match:
166
+ - `safedeps/__init__.py` (`__version__`)
167
+ - `packages/npm-wrapper/package.json` (`version`)
168
+ - Release tags must follow `vX.Y.Z`.
169
+ - No package publish if versions are inconsistent.
170
+ - CI enforces this with `python scripts/check_versions.py`.
171
+
172
+ ## Features
173
+
174
+ - Central policy file: `.safedeps/policy.json`
175
+ - Python scanning:
176
+ - `requirements*.txt`
177
+ - npm scanning:
178
+ - `package.json`
179
+ - `.npmrc`
180
+ - lockfile presence checks
181
+ - install lifecycle scripts checks
182
+ - `pnpm-lock.yaml` deep parsing (PyYAML-backed)
183
+ - .NET scanning:
184
+ - `.csproj`
185
+ - `NuGet.Config`
186
+ - lockfile presence checks
187
+ - Git dependency checks:
188
+ - `.gitmodules`
189
+ - Rule enforcement:
190
+ - denylist packages
191
+ - floating/unpinned versions
192
+ - untrusted registries/indexes
193
+ - expired exceptions
194
+ - runtime strict checks for `pip`, `python -m pip`, and `npm` guarded wrappers
195
+ - CI-friendly exit codes
196
+
197
+ ## Install
198
+
199
+ ### Python (local development)
200
+
201
+ ```bash
202
+ pip install .
203
+ ```
204
+
205
+ Install with development tooling (tests):
206
+
207
+ ```bash
208
+ pip install .[dev]
209
+ ```
210
+
211
+ Or bootstrap a local virtual environment automatically:
212
+
213
+ ```bash
214
+ ./scripts/bootstrap_dev.sh
215
+ ```
216
+
217
+ Windows manual setup:
218
+
219
+ ```powershell
220
+ py -m venv .venv-test
221
+ .\.venv-test\Scripts\Activate.ps1
222
+ pip install -e .[dev]
223
+ ```
224
+
225
+ ### Python (from PyPI, after publish)
226
+
227
+ ```bash
228
+ pip install safedeps
229
+ ```
230
+
231
+ ### npm (from wrapper package)
232
+
233
+ From this repository:
234
+
235
+ ```bash
236
+ cd packages/npm-wrapper
237
+ npm install -g .
238
+ ```
239
+
240
+ From npm registry (after publish):
241
+
242
+ ```bash
243
+ npm install -g @jaydemks/safedeps
244
+ ```
245
+
246
+ Note: npm runtime flow is implemented, but full cross-environment validation is still in progress.
247
+
248
+ ### .NET
249
+
250
+ From this repository (after pack/install):
251
+
252
+ ```bash
253
+ dotnet tool install --global --add-source ./artifacts/dotnet SafeDeps.Tool
254
+ ```
255
+
256
+ Command:
257
+
258
+ ```bash
259
+ safedeps-dotnet scan .
260
+ ```
261
+
262
+ From NuGet (after publish):
263
+
264
+ ```bash
265
+ dotnet tool install -g SafeDeps.Tool
266
+ ```
267
+
268
+ Note: NuGet/.NET runtime flow is implemented, but full cross-environment validation is still in progress.
269
+
270
+ ## Quickstart
271
+
272
+ ```bash
273
+ safedeps init
274
+ safedeps scan .
275
+ ```
276
+
277
+ One-time project auto-configuration (guard `pip install` automatically in this project shell):
278
+
279
+ ```bash
280
+ safedeps setup .
281
+ source .safedeps/activate.sh
282
+ ```
283
+
284
+ Windows (PowerShell):
285
+
286
+ ```powershell
287
+ python -m safedeps.cli setup .
288
+ . .\.safedeps\activate.ps1
289
+ ```
290
+
291
+ Quick help command (terminal/cmd/powershell):
292
+
293
+ ```bash
294
+ safedeps help
295
+ ```
296
+
297
+ Fail CI on high/critical findings:
298
+
299
+ ```bash
300
+ safedeps scan . --fail-on HIGH
301
+ ```
302
+
303
+ Optional online npm audit:
304
+
305
+ ```bash
306
+ safedeps scan . --online-audit
307
+ ```
308
+
309
+ Optional SARIF export:
310
+
311
+ ```bash
312
+ safedeps scan . --sarif security-artifacts/safedeps.sarif
313
+ ```
314
+
315
+ Optional CycloneDX export:
316
+
317
+ ```bash
318
+ safedeps scan . --cyclonedx security-artifacts/safedeps.cdx.json
319
+ ```
320
+
321
+ Optional SPDX export:
322
+
323
+ ```bash
324
+ safedeps scan . --spdx security-artifacts/safedeps.spdx.json
325
+ ```
326
+
327
+ Optional HTML export:
328
+
329
+ ```bash
330
+ safedeps scan . --html security-artifacts/safedeps-report.html
331
+ ```
332
+
333
+ Exporter notes:
334
+
335
+ - SARIF includes rule catalog and severity mapping.
336
+ - CycloneDX/SPDX exporters deduplicate repeated components.
337
+ - SPDX and CycloneDX include purl metadata when manager/version are available.
338
+
339
+ Validate local setup and metadata cache health:
340
+
341
+ ```bash
342
+ safedeps doctor .
343
+ ```
344
+
345
+ Explain a specific finding rule:
346
+
347
+ ```bash
348
+ safedeps explain FLOATING_VERSION
349
+ ```
350
+
351
+ Create vulnerability baseline from the latest report:
352
+
353
+ ```bash
354
+ safedeps baseline . --report security-artifacts/safedeps-report.json --output .safedeps/vuln-baseline.json
355
+ ```
356
+
357
+ Add/update an expiring suppression entry:
358
+
359
+ ```bash
360
+ safedeps approve . --manager npm --rule FLOATING_VERSION --package lodash --file package.json --expires 2026-12-31
361
+ ```
362
+
363
+ Run the local visual UI:
364
+
365
+ ```bash
366
+ python -m safedeps.cli ui . --host 127.0.0.1 --port 8877 --open-browser
367
+ ```
368
+
369
+ The UI is fully in English and includes visual flows for:
370
+
371
+ - initial auto-scan on UI open + `Re-Scan`
372
+ - dependency inventory table with quick approval action
373
+ - direct per-row `Uninstall` and `Safe Update` actions
374
+ - rule explanation (`explain`)
375
+ - baseline generation (`baseline`)
376
+ - expiring approvals (`approve --expires`)
377
+ - one-click finding pickup ("Use For Approval") to prefill approval fields
378
+ - policy quick editor for allowlist registries and deny packages
379
+ - pip install guard panel showing blocking pip findings and reasons
380
+ - intelligence editor for `.safedeps/vuln-feed.json` and `.safedeps/metadata-cache.json`
381
+ - one-click starter template generation for local "safe" intelligence files
382
+ - light/dark theme toggle persisted in browser
383
+ - dynamic partial refresh for scan/dependency actions (reduced full-page reload behavior)
384
+
385
+ UI options:
386
+
387
+ - `--host` (default `127.0.0.1`)
388
+ - `--port` (default `8765`)
389
+ - `--fail-on` (default `HIGH`)
390
+
391
+ Protection scope behavior:
392
+
393
+ - `Project Only`: guard blocks runtime dependency changes only when working inside this project path.
394
+ - `Global`: guard blocks runtime dependency changes both inside and outside this project path.
395
+ - UI toggles are available under guard controls:
396
+ - `Scope: Project Only`
397
+ - `Scope: Global`
398
+ - Default scope:
399
+ - if SafeDeps runs inside a virtual environment: `Project Only`
400
+ - if SafeDeps runs system-wide: `Global`
401
+
402
+ ## Minimal Policy Example
403
+
404
+ ```json
405
+ {
406
+ "allowed_registries": {
407
+ "npm": ["https://registry.npmjs.org/"],
408
+ "pip": ["https://pypi.org/simple", "https://pypi.org/simple/"],
409
+ "nuget": ["https://api.nuget.org/v3/index.json"]
410
+ },
411
+ "deny_packages": ["malicious-demo-package"],
412
+ "allow_unpinned": false,
413
+ "require_lockfiles": true,
414
+ "require_expiring_exceptions": true,
415
+ "exceptions": [
416
+ {
417
+ "manager": "npm",
418
+ "package": "demo-package",
419
+ "rule": "FLOATING_VERSION",
420
+ "expires": "2026-12-31",
421
+ "reason": "Temporary migration exception"
422
+ }
423
+ ]
424
+ }
425
+ ```
426
+
427
+ Vulnerability baseline support:
428
+
429
+ - Default file: `.safedeps/vuln-baseline.json`
430
+ - Matching findings can be suppressed via `suppress` entries (`manager`, `rule`, `package`, `file`).
431
+ - Suppression entries may include optional `expires` (`YYYY-MM-DD`); expired entries are ignored.
432
+
433
+ Local vulnerability feed support:
434
+
435
+ - Optional file: `.safedeps/vuln-feed.json`
436
+ - Supported fields per entry: `manager`, `package`, `id`, `severity`, `message`
437
+ - Optional OSV-style entries via `vulnerabilities_osv` are also supported in `.safedeps/vuln-feed.json`.
438
+ - Severity is normalized to SafeDeps scale (`CRITICAL/HIGH/MEDIUM/LOW/INFO`).
439
+ - You can create/edit/validate this file directly from the UI ("Intelligence Settings"), no manual file editing required.
440
+
441
+ Local metadata cache support:
442
+
443
+ - Optional file: `.safedeps/metadata-cache.json`
444
+ - Used by age/churn/maintainer risk signals.
445
+ - You can create/edit/validate this file directly from the UI ("Intelligence Settings").
446
+
447
+ ## Verification Workflow
448
+
449
+ Run these checks before release:
450
+
451
+ 1. `safedeps scan examples/bad-project` must fail (`exit code 2`).
452
+ 2. `safedeps scan examples/safe-project` should pass or produce only accepted non-blocking findings.
453
+ 3. `python -m pytest` must pass.
454
+ 4. CI must fail on an intentionally unsafe fixture branch.
455
+
456
+ ## Publishing
457
+
458
+ ### Python / PyPI
459
+
460
+ ```bash
461
+ python -m build
462
+ python -m twine upload dist/*
463
+ ```
464
+
465
+ ### npm
466
+
467
+ ```bash
468
+ cd packages/npm-wrapper
469
+ npm publish --access public
470
+ ```
471
+
472
+ ### .NET / NuGet (planned)
473
+
474
+ ```bash
475
+ dotnet pack packages/dotnet-tool/SafeDeps.Tool.csproj -c Release -o artifacts/dotnet
476
+ dotnet nuget push artifacts/dotnet/*.nupkg --source https://api.nuget.org/v3/index.json --api-key YOUR_KEY
477
+ ```
478
+
479
+ Use trusted publishing/OIDC whenever available.
480
+
481
+ ## Release Automation (Template)
482
+
483
+ Run local preflight checks before triggering a release:
484
+
485
+ ```bash
486
+ python scripts/release/preflight.py --expected-version 0.2.7
487
+ ```
488
+
489
+ Release workflow template:
490
+
491
+ - `.github/workflows/release-template.yml`
492
+ - includes:
493
+ - preflight checks
494
+ - Python distribution build artifact
495
+ - npm wrapper tarball artifact
496
+ - .NET tool `.nupkg` artifact
497
+ - release checksum manifest (`release-artifacts/release-manifest.json`)
498
+ - optional publish gates (`publish=true`) for PyPI/npm/NuGet
499
+ - tag-triggered release flow on `v*` tags
500
+ - GitHub release publication with attached artifacts
501
+ - build provenance attestation stage
502
+
503
+ Detailed process guide:
504
+
505
+ - `docs/release/RELEASE_PROCESS.md`
506
+
507
+ Artifact validation helper:
508
+
509
+ ```bash
510
+ python scripts/validate_artifacts.py security-artifacts
511
+ ```
512
+
513
+ ## CI Templates
514
+
515
+ Ready-to-copy templates are available in `examples/ci/` for:
516
+
517
+ - GitHub Actions
518
+ - GitLab CI
519
+ - Azure Pipelines
520
+
521
+ See `examples/ci/README.md` for usage details.
522
+
523
+ ## Pre-commit Integration
524
+
525
+ This repository includes a ready pre-commit hook config:
526
+
527
+ - `.pre-commit-config.yaml`
528
+
529
+ Install and enable:
530
+
531
+ ```bash
532
+ pip install pre-commit
533
+ pre-commit install
534
+ ```
535
+
536
+ The hook runs:
537
+
538
+ ```bash
539
+ safedeps scan . --fail-on HIGH --out security-artifacts
540
+ ```
541
+
542
+ ## Security Scope
543
+
544
+ SafeDeps is a preventive gate, not a guarantee that every package is safe.
545
+
546
+ It should be used with lockfiles, code review, SBOM analysis, vulnerability feeds, signed releases where supported, and CI policy enforcement.