secretscreen 0.5.1__tar.gz → 0.6.0__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.
Files changed (47) hide show
  1. secretscreen-0.6.0/.github/dependabot.yml +43 -0
  2. secretscreen-0.6.0/.github/workflows/automerge.yml +48 -0
  3. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/workflows/ci.yml +5 -2
  4. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/workflows/codeql.yml +3 -3
  5. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/workflows/publish.yml +6 -0
  6. secretscreen-0.6.0/.github/workflows/release.yml +132 -0
  7. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/workflows/scorecard.yml +1 -1
  8. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/workflows/test-gate.yml +22 -0
  9. {secretscreen-0.5.1 → secretscreen-0.6.0}/PKG-INFO +7 -7
  10. {secretscreen-0.5.1 → secretscreen-0.6.0}/README.md +2 -2
  11. {secretscreen-0.5.1 → secretscreen-0.6.0}/pyproject.toml +35 -5
  12. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/__init__.py +11 -1
  13. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_cli.py +6 -1
  14. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_core.py +27 -12
  15. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_architecture.py +35 -10
  16. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_core.py +50 -12
  17. secretscreen-0.5.1/.github/dependabot.yml +0 -33
  18. secretscreen-0.5.1/.github/workflows/dependabot-automerge.yml +0 -29
  19. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/FUNDING.yml +0 -0
  20. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  21. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/pull_request_template.md +0 -0
  22. {secretscreen-0.5.1 → secretscreen-0.6.0}/.github/scripts/pr_test_gate.py +0 -0
  23. {secretscreen-0.5.1 → secretscreen-0.6.0}/.gitignore +0 -0
  24. {secretscreen-0.5.1 → secretscreen-0.6.0}/CODE_OF_CONDUCT.md +0 -0
  25. {secretscreen-0.5.1 → secretscreen-0.6.0}/CONTRIBUTING.md +0 -0
  26. {secretscreen-0.5.1 → secretscreen-0.6.0}/LICENSE +0 -0
  27. {secretscreen-0.5.1 → secretscreen-0.6.0}/NOTICE +0 -0
  28. {secretscreen-0.5.1 → secretscreen-0.6.0}/SECURITY.md +0 -0
  29. {secretscreen-0.5.1 → secretscreen-0.6.0}/docs/audits/security-audit-2026-04-05.md +0 -0
  30. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_config.py +0 -0
  31. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_entropy.py +0 -0
  32. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_formats.py +0 -0
  33. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_keys.py +0 -0
  34. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_parsers.py +0 -0
  35. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/_urls.py +0 -0
  36. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/gitleaks.toml +0 -0
  37. {secretscreen-0.5.1 → secretscreen-0.6.0}/src/secretscreen/py.typed +0 -0
  38. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/__init__.py +0 -0
  39. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_cli.py +0 -0
  40. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_config.py +0 -0
  41. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_entropy.py +0 -0
  42. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_explain.py +0 -0
  43. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_formats.py +0 -0
  44. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_keys.py +0 -0
  45. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_parsers.py +0 -0
  46. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_urls.py +0 -0
  47. {secretscreen-0.5.1 → secretscreen-0.6.0}/tests/test_yaml_and_prefixes.py +0 -0
@@ -0,0 +1,43 @@
1
+ version: 2
2
+ updates:
3
+ # Prefixes follow one rule: "deps:" for anything that reaches a user, which
4
+ # cuts a patch release; "chore(...)" for anything that does not.
5
+ #
6
+ # secretscreen has NO runtime dependencies — the pip ecosystem here sees only
7
+ # dev tooling (pytest, ruff, mypy). A ruff bump must not cut a release of a
8
+ # library whose code did not change, so pip stays on "chore" and dependabot's
9
+ # own scope distinguishes deps from deps-dev. Switch pip to "deps" the day a
10
+ # real runtime dependency is added.
11
+ - package-ecosystem: pip
12
+ directory: /
13
+ schedule:
14
+ interval: daily
15
+ cooldown:
16
+ semver-major-days: 30
17
+ semver-minor-days: 7
18
+ semver-patch-days: 3
19
+ groups:
20
+ pip-patches:
21
+ update-types: ["patch"]
22
+ commit-message:
23
+ prefix: chore
24
+ include: scope
25
+ labels:
26
+ - dependencies
27
+
28
+ - package-ecosystem: github-actions
29
+ directory: /
30
+ schedule:
31
+ interval: weekly
32
+ cooldown:
33
+ semver-major-days: 30
34
+ semver-minor-days: 7
35
+ semver-patch-days: 3
36
+ groups:
37
+ actions:
38
+ patterns: ["*"]
39
+ commit-message:
40
+ prefix: chore
41
+ include: scope
42
+ labels:
43
+ - dependencies
@@ -0,0 +1,48 @@
1
+ name: Auto-merge
2
+
3
+ # main-protection requires one approving review. GitHub forbids self-approval and
4
+ # only one account has write access, so that rule was unsatisfiable and every
5
+ # merge became an admin bypass. This turns the approval into an author allowlist,
6
+ # which is what the rule was actually for.
7
+ on:
8
+ pull_request_target:
9
+
10
+ permissions:
11
+ contents: write
12
+ pull-requests: write
13
+
14
+ jobs:
15
+ automerge:
16
+ # pull_request.user.login is the PR author. github.actor is whoever triggered
17
+ # the event, which is not the same thing on pull_request_target.
18
+ if: >-
19
+ contains(fromJSON('["dependabot[bot]", "featurecreep-cron",
20
+ "github-actions[bot]", "featurecreep-promoter[bot]"]'),
21
+ github.event.pull_request.user.login)
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ # No checkout anywhere in this job. pull_request_target runs with repository
25
+ # secrets, so checking out PR head code would hand them to the PR author.
26
+ - name: Generate token
27
+ id: generate_token
28
+ uses: actions/create-github-app-token@v3
29
+ with:
30
+ app-id: ${{ secrets.BOT_APP_ID }}
31
+ private-key: ${{ secrets.BOT_PRIVATE_KEY }}
32
+
33
+ - name: Approve PR
34
+ uses: hmarr/auto-approve-action@b40d6c9ed2fa10c9a2749eca7eb004418a705501
35
+ with:
36
+ github-token: ${{ steps.generate_token.outputs.token }}
37
+
38
+ # Must be the app token, not GITHUB_TOKEN. GitHub does not start new
39
+ # workflow runs for events triggered by GITHUB_TOKEN, so an auto-merge
40
+ # enabled with it lands the commit and then runs nothing.
41
+ #
42
+ # --merge, not --rebase: rebasing a develop -> main promotion would give
43
+ # main new SHAs for develop's commits and diverge the branches.
44
+ - name: Enable auto-merge
45
+ run: gh pr merge --auto --merge "$PR_URL"
46
+ env:
47
+ PR_URL: ${{ github.event.pull_request.html_url }}
48
+ GH_TOKEN: ${{ steps.generate_token.outputs.token }}
@@ -2,12 +2,15 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [main]
5
+ branches: [main, develop]
6
6
  # No `branches:` filter. Gating on the base branch means a stacked pull
7
7
  # request — one opened against another feature branch — runs nothing, and
8
8
  # reports only the skipped automerge job, which reads like a pass. Push is
9
- # still limited to main so feature-branch pushes do not double-run.
9
+ # limited to the long-lived branches so feature-branch pushes do not
10
+ # double-run.
10
11
  pull_request:
12
+ # Called by release.yml to verify main before anything is tagged.
13
+ workflow_call:
11
14
 
12
15
  concurrency:
13
16
  group: ${{ github.workflow }}-${{ github.ref }}
@@ -21,12 +21,12 @@ jobs:
21
21
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
22
22
 
23
23
  - name: Initialize CodeQL
24
- uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
24
+ uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
25
25
  with:
26
26
  languages: python
27
27
 
28
28
  - name: Autobuild
29
- uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
29
+ uses: github/codeql-action/autobuild@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
30
30
 
31
31
  - name: Perform CodeQL Analysis
32
- uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
32
+ uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
@@ -14,6 +14,12 @@ jobs:
14
14
 
15
15
  steps:
16
16
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
17
+ with:
18
+ # Build the released tag, not the default branch, and with full
19
+ # history: hatch-vcs derives the version from the tag, so a shallow
20
+ # or wrong-ref checkout publishes the wrong version.
21
+ ref: ${{ github.event.release.tag_name }}
22
+ fetch-depth: 0
17
23
 
18
24
  - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
19
25
  with:
@@ -0,0 +1,132 @@
1
+ name: Release
2
+
3
+ # Releases are deliberate, not a side effect of merging. workflow_dispatch is
4
+ # the normal path; the weekly schedule is the floor, so a maintainer absent for
5
+ # months does not leave fixes sitting on develop unreleased.
6
+ on:
7
+ workflow_dispatch:
8
+ inputs:
9
+ force:
10
+ description: "Force version bump type (leave empty for auto-detect)"
11
+ required: false
12
+ type: choice
13
+ options:
14
+ - ""
15
+ - "patch"
16
+ - "minor"
17
+ - "major"
18
+ schedule:
19
+ - cron: "0 6 * * 1"
20
+
21
+ permissions:
22
+ contents: read
23
+
24
+ concurrency:
25
+ group: release
26
+ cancel-in-progress: false
27
+
28
+ jobs:
29
+ # Promote develop -> main through a PR, not a direct push. Nothing is exempt
30
+ # from main-protection: the PR is approved by the automerge workflow's author
31
+ # allowlist and merged by auto-merge once the required checks are green.
32
+ promote:
33
+ runs-on: ubuntu-latest
34
+ permissions:
35
+ contents: write
36
+ pull-requests: write
37
+ steps:
38
+ # A second app, distinct from the one that approves: GitHub refuses
39
+ # self-approval, so the opener and the approver cannot be the same
40
+ # identity. Keeps the promotion inside the normal PR path with nothing
41
+ # exempt from main-protection.
42
+ - name: Generate promoter token
43
+ id: promoter
44
+ uses: actions/create-github-app-token@v3
45
+ with:
46
+ app-id: ${{ secrets.PROMOTER_APP_ID }}
47
+ private-key: ${{ secrets.PROMOTER_PRIVATE_KEY }}
48
+
49
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
50
+ with:
51
+ fetch-depth: 0
52
+
53
+ - name: Open promotion PR and wait for it to merge
54
+ env:
55
+ GH_TOKEN: ${{ steps.promoter.outputs.token }}
56
+ run: |
57
+ set -euo pipefail
58
+
59
+ if git diff --quiet origin/main origin/develop; then
60
+ echo "develop and main are identical — nothing to promote."
61
+ exit 0
62
+ fi
63
+
64
+ pr=$(gh pr list --base main --head develop --state open \
65
+ --json number --jq '.[0].number // empty')
66
+ if [ -z "$pr" ]; then
67
+ pr=$(gh pr create --base main --head develop \
68
+ --title "release: promote develop to main" \
69
+ --body "Automated promotion. Merged by auto-merge once CI is green." \
70
+ | grep -oE '[0-9]+$')
71
+ echo "opened PR #$pr"
72
+ else
73
+ echo "reusing open PR #$pr"
74
+ fi
75
+
76
+ # Auto-merge is enabled by automerge.yml, which fires on this PR and
77
+ # approves it as a different identity. Doing it here as well needs
78
+ # permissions the promoter does not have, and does not need:
79
+ # "Resource not accessible by integration (enablePullRequestAutoMerge)".
80
+
81
+ for _ in $(seq 1 60); do
82
+ state=$(gh pr view "$pr" --json state --jq .state)
83
+ [ "$state" = "MERGED" ] && { echo "promotion merged"; exit 0; }
84
+ [ "$state" = "CLOSED" ] && { echo "::error::promotion PR was closed"; exit 1; }
85
+ sleep 30
86
+ done
87
+ echo "::error::promotion PR #$pr did not merge within 30 minutes"
88
+ exit 1
89
+
90
+ # Run the suite against main as it now stands, before anything is tagged.
91
+ verify:
92
+ needs: promote
93
+ uses: ./.github/workflows/ci.yml
94
+ secrets: inherit
95
+
96
+ release:
97
+ needs: verify
98
+ runs-on: ubuntu-latest
99
+ permissions:
100
+ contents: write
101
+ steps:
102
+ # The app token, not GITHUB_TOKEN. psr creates the GitHub Release, and
103
+ # publish.yml fires on `release: published` — an event triggered by
104
+ # GITHUB_TOKEN starts no workflow run, so the package would never be
105
+ # published. This is the one credential this workflow needs.
106
+ - name: Generate token
107
+ id: generate_token
108
+ uses: actions/create-github-app-token@v3
109
+ with:
110
+ app-id: ${{ secrets.BOT_APP_ID }}
111
+ private-key: ${{ secrets.BOT_PRIVATE_KEY }}
112
+
113
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
114
+ with:
115
+ ref: main
116
+ fetch-depth: 0
117
+ token: ${{ steps.generate_token.outputs.token }}
118
+
119
+ # Tag-only. hatch-vcs derives the version from the tag, so there is no
120
+ # file to write and no commit to make — which means no push to a protected
121
+ # branch and no bypass actor anywhere. Rulesets cover branches, not tags.
122
+ - name: Python Semantic Release
123
+ uses: python-semantic-release/python-semantic-release@9a026e9303981c866c3425723009becb2437c757 # v10.6.2
124
+ with:
125
+ github_token: ${{ steps.generate_token.outputs.token }}
126
+ force: ${{ github.event.inputs.force || '' }}
127
+ commit: "false"
128
+ changelog: "false"
129
+ tag: "true"
130
+ push: "true"
131
+ vcs_release: "true"
132
+ build: "false"
@@ -30,6 +30,6 @@ jobs:
30
30
  publish_results: true
31
31
 
32
32
  - name: Upload to code-scanning
33
- uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
33
+ uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
34
34
  with:
35
35
  sarif_file: results.sarif
@@ -59,3 +59,25 @@ jobs:
59
59
  echo "::notice::Test gate skipped via the no-test-gate label."
60
60
  echo "This pull request claims it changes no behaviour."
61
61
  echo "That claim is the reviewer's to check."
62
+
63
+ # A required status check has to report on EVERY pull request. `gate` and
64
+ # `exempt` are mutually exclusive and both skip on Dependabot PRs, so
65
+ # requiring either directly would block those PRs forever waiting for a check
66
+ # that never runs. This job always reports, and fails only when the gate
67
+ # actually failed — which is what makes the gate enforceable rather than
68
+ # advisory. Require THIS check, not `gate`.
69
+ gate-result:
70
+ needs: [gate, exempt]
71
+ if: always()
72
+ runs-on: ubuntu-latest
73
+ steps:
74
+ - name: Report the gate outcome
75
+ run: |
76
+ echo "gate=${{ needs.gate.result }} exempt=${{ needs.exempt.result }}"
77
+ if [ "${{ needs.gate.result }}" = "failure" ]; then
78
+ echo "::error::The test gate failed: no added test fails against base source."
79
+ exit 1
80
+ fi
81
+ if [ "${{ needs.exempt.result }}" = "success" ]; then
82
+ echo "::notice::Exempted via the no-test-gate label."
83
+ fi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: secretscreen
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: Detect and redact secrets in key-value pairs, dicts, and environment variables. Library and CLI.
5
5
  Project-URL: Homepage, https://github.com/featurecreep-cron/secretscreen
6
6
  Project-URL: Repository, https://github.com/featurecreep-cron/secretscreen
@@ -24,10 +24,10 @@ Classifier: Topic :: Utilities
24
24
  Classifier: Typing :: Typed
25
25
  Requires-Python: >=3.11
26
26
  Provides-Extra: dev
27
- Requires-Dist: mypy<3,>=2.3.0; extra == 'dev'
28
- Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
29
- Requires-Dist: pytest>=9.1.1; extra == 'dev'
30
- Requires-Dist: ruff<0.17,>=0.16.0; extra == 'dev'
27
+ Requires-Dist: mypy==2.3.1; extra == 'dev'
28
+ Requires-Dist: pytest-cov==7.1.0; extra == 'dev'
29
+ Requires-Dist: pytest==9.1.1; extra == 'dev'
30
+ Requires-Dist: ruff==0.16.5; extra == 'dev'
31
31
  Description-Content-Type: text/markdown
32
32
 
33
33
  # secretscreen
@@ -201,7 +201,7 @@ secretscreen: explain — key names and reasons only, no values
201
201
  unscanned BACKUP_BLOB - 2202009 bytes exceeds the 65536-byte scan cap
202
202
  ```
203
203
 
204
- Four states. `redacted` and `clean` are self-explanatory; the two in between are the ones worth reading. **`vetoed`** means a rule fired and something suppressed it — that is where the tool decided to stay quiet. **`unscanned`** means the size cap skipped the value-scanning layers.
204
+ Four states. `redacted` and `clean` are self-explanatory; the two in between are the ones worth reading. **`vetoed`** means a rule fired and something suppressed it — that is where the tool decided to stay quiet. **`unscanned`** means the size cap skipped the value-scanning layers, so the value is redacted on the grounds that it was never examined — an unscanned value is not a clean one.
205
205
 
206
206
  Clean lines carry the nearest miss rather than silence. The entropy figure is computed even in normal mode, where that layer never runs, so you can see what `--aggressive` would change before turning it on.
207
207
 
@@ -215,7 +215,7 @@ Like `--audit`, this never prints a value — paste it into a bug report as-is.
215
215
  | 1 | `--audit` found secrets |
216
216
  | 2 | Something could not be parsed or read — see stderr |
217
217
 
218
- That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are reported as unscanned rather than passed off as clean.
218
+ That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are redacted and reported as unscanned rather than passed off as clean. That holds in the library too, not just the CLI: `redact_pair` returns the replacement and `audit_pair` returns a `size_cap` finding, so a consumer cannot mistake *not examined* for *examined and clean*.
219
219
 
220
220
  If you are scanning a git repository rather than config-shaped data, use [gitleaks](https://github.com/gitleaks/gitleaks) instead. That is a different job.
221
221
 
@@ -169,7 +169,7 @@ secretscreen: explain — key names and reasons only, no values
169
169
  unscanned BACKUP_BLOB - 2202009 bytes exceeds the 65536-byte scan cap
170
170
  ```
171
171
 
172
- Four states. `redacted` and `clean` are self-explanatory; the two in between are the ones worth reading. **`vetoed`** means a rule fired and something suppressed it — that is where the tool decided to stay quiet. **`unscanned`** means the size cap skipped the value-scanning layers.
172
+ Four states. `redacted` and `clean` are self-explanatory; the two in between are the ones worth reading. **`vetoed`** means a rule fired and something suppressed it — that is where the tool decided to stay quiet. **`unscanned`** means the size cap skipped the value-scanning layers, so the value is redacted on the grounds that it was never examined — an unscanned value is not a clean one.
173
173
 
174
174
  Clean lines carry the nearest miss rather than silence. The entropy figure is computed even in normal mode, where that layer never runs, so you can see what `--aggressive` would change before turning it on.
175
175
 
@@ -183,7 +183,7 @@ Like `--audit`, this never prints a value — paste it into a bug report as-is.
183
183
  | 1 | `--audit` found secrets |
184
184
  | 2 | Something could not be parsed or read — see stderr |
185
185
 
186
- That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are reported as unscanned rather than passed off as clean.
186
+ That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are redacted and reported as unscanned rather than passed off as clean. That holds in the library too, not just the CLI: `redact_pair` returns the replacement and `audit_pair` returns a `size_cap` finding, so a consumer cannot mistake *not examined* for *examined and clean*.
187
187
 
188
188
  If you are scanning a git repository rather than config-shaped data, use [gitleaks](https://github.com/gitleaks/gitleaks) instead. That is a different job.
189
189
 
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["hatchling"]
2
+ requires = ["hatchling", "hatch-vcs>=0.4"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "secretscreen"
7
- version = "0.5.1"
7
+ dynamic = ["version"]
8
8
  description = "Detect and redact secrets in key-value pairs, dicts, and environment variables. Library and CLI."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -30,9 +30,11 @@ classifiers = [
30
30
  secretscreen = "secretscreen._cli:main"
31
31
 
32
32
  [project.optional-dependencies]
33
- # Linters gate CI, so they carry upper bounds: an unpinned ruff minor bump
34
- # (0.15 -> 0.16) silently changed formatting rules and broke an unrelated PR.
35
- dev = ["pytest>=9.1.1", "pytest-cov>=7.1.0", "ruff>=0.16.0,<0.17", "mypy>=2.3.0,<3"]
33
+ # Pinned exactly, like every other dependency in these repos. The reason the
34
+ # linters previously carried upper bounds still applies and is now covered by
35
+ # the pin: an unpinned ruff minor bump (0.15 -> 0.16) silently changed
36
+ # formatting rules and broke an unrelated PR.
37
+ dev = ["pytest==9.1.1", "pytest-cov==7.1.0", "ruff==0.16.5", "mypy==2.3.1"]
36
38
 
37
39
  [project.urls]
38
40
  Homepage = "https://github.com/featurecreep-cron/secretscreen"
@@ -70,3 +72,31 @@ line-length = 120
70
72
  [tool.ruff.lint]
71
73
  select = ["E", "F", "W", "I", "N", "UP", "B", "A", "SIM", "TCH"]
72
74
  ignore = ["SIM102", "SIM108"]
75
+
76
+ [tool.hatch.version]
77
+ # The git tag is the single source of the version. Nothing writes it into a
78
+ # file, so pyproject and the tag cannot drift apart.
79
+ source = "vcs"
80
+
81
+ [tool.semantic_release]
82
+ commit_parser = "conventional"
83
+ tag_format = "v{version}"
84
+ major_on_zero = false
85
+ allow_zero_version = true
86
+
87
+ [tool.semantic_release.commit_parser_options]
88
+ minor_tags = ["feat"]
89
+ # "deps" is a patch-producing type across our repos. secretscreen has no runtime
90
+ # dependencies today so nothing emits it here, but the parser should agree with
91
+ # the others the day that changes. allowed_tags must be listed explicitly: its
92
+ # default is computed from the class-level defaults, so overriding patch_tags
93
+ # alone leaves "deps" unrecognised and silently drops every such commit.
94
+ patch_tags = ["fix", "perf", "deps"]
95
+ allowed_tags = [
96
+ "feat", "fix", "perf", "deps",
97
+ "build", "chore", "ci", "docs", "style", "refactor", "test",
98
+ ]
99
+
100
+ [tool.semantic_release.branches.main]
101
+ match = "main"
102
+ prerelease = false
@@ -19,6 +19,9 @@ Two modes:
19
19
  audit_pair() and audit_dict() return structured findings without mutating values.
20
20
  """
21
21
 
22
+ from importlib.metadata import PackageNotFoundError
23
+ from importlib.metadata import version as _metadata_version
24
+
22
25
  from secretscreen._core import (
23
26
  Finding,
24
27
  Mode,
@@ -37,4 +40,11 @@ __all__ = [
37
40
  "redact_pair",
38
41
  ]
39
42
 
40
- __version__ = "0.5.1"
43
+ # Read from installed metadata, which hatch-vcs derives from the git tag. A
44
+ # hardcoded literal here would be a second source of truth and would drift the
45
+ # moment a release is cut — `--version` would then report a version that is not
46
+ # the one the user installed.
47
+ try:
48
+ __version__ = _metadata_version("secretscreen")
49
+ except PackageNotFoundError: # running from a source tree without an install
50
+ __version__ = "0.0.0+dev"
@@ -348,7 +348,12 @@ def _redact_value(key: str, value: str, settings: _Settings, replacement: str) -
348
348
  result = redact_pair(
349
349
  key, value, mode=settings.mode, replacement=replacement, entropy_threshold=settings.entropy_threshold
350
350
  )
351
- unscanned = len(value) > _MAX_DETECT_LENGTH and result == value
351
+ # Ask the library rather than re-deriving it from the size. The old form
352
+ # inferred unscanned from `oversized and unchanged`, which duplicated a
353
+ # private constant and stopped being true once redaction started failing
354
+ # closed. secretscreen now reports the state directly.
355
+ finding = audit_pair(key, value, mode=settings.mode, entropy_threshold=settings.entropy_threshold)
356
+ unscanned = finding is not None and finding.layer == "size_cap"
352
357
  return result, unscanned
353
358
 
354
359
 
@@ -241,9 +241,28 @@ def _detect_with_pairs(
241
241
  None,
242
242
  )
243
243
 
244
- # Layers 2-5 all scan the value itself. Stop here for oversized input.
244
+ # Layers 2-5 all scan the value itself, and an oversized value cannot be
245
+ # screened. Returning "no finding" here would be indistinguishable from
246
+ # "scanned and clean", so redact_pair would hand back an unexamined value
247
+ # and audit_pair would call it clean. Fail closed instead: report it as
248
+ # unscanned, which redacts it and shows up in an audit.
249
+ #
250
+ # The alternative — passing it through and expecting callers to notice —
251
+ # was tried and did not hold. The CLI re-derived the check by hand and a
252
+ # library consumer had no way to, so an unexamined value was printed as
253
+ # though it had been screened.
245
254
  if oversized:
246
- return (None, None)
255
+ return (
256
+ Finding(
257
+ key=key,
258
+ reason="unscanned:size",
259
+ layer="size_cap",
260
+ detail=(
261
+ f"{len(value)} bytes exceeds the {_MAX_DETECT_LENGTH}-byte scan cap; the value was not examined"
262
+ ),
263
+ ),
264
+ None,
265
+ )
247
266
 
248
267
  # Layer 4: URL credential detection (even without key pattern match)
249
268
  if has_url_credentials(value):
@@ -524,18 +543,14 @@ def _explain(key: str, value: str, config: ScreenConfig) -> Explanation:
524
543
 
525
544
  finding = _detect(key, value, config)
526
545
  if finding is not None:
546
+ # Redacted-because-unexaminable is a different fact from
547
+ # redacted-because-a-secret-was-found, and a reader needs to tell them
548
+ # apart. Layer 1 still wins for an oversized value under a secret key
549
+ # name, so that case reports as redacted, which is accurate.
550
+ if finding.layer == "size_cap":
551
+ return Explanation(key, STATE_UNSCANNED, finding.layer, finding.detail or "")
527
552
  return Explanation(key, STATE_REDACTED, finding.layer, _describe_finding(finding, value))
528
553
 
529
- # Order matters: layer 1 still redacts an oversized value under a secret
530
- # key name, so the size skip is only reported once detection has declined.
531
- if len(value) > _MAX_DETECT_LENGTH:
532
- return Explanation(
533
- key,
534
- STATE_UNSCANNED,
535
- "",
536
- f"{len(value)} bytes exceeds the {_MAX_DETECT_LENGTH}-byte scan cap",
537
- )
538
-
539
554
  vetoed = _vetoed_by_safe_suffix(key, config)
540
555
  if vetoed is not None:
541
556
  pattern, suffix = vetoed
@@ -268,28 +268,53 @@ class TestNoSideEffects:
268
268
 
269
269
 
270
270
  class TestVersionSync:
271
- """pyproject version and __version__ must agree.
271
+ """There must be exactly one source of the version.
272
272
 
273
- Nothing else enforces this, and a drift ships a wheel whose metadata
274
- disagrees with the value the library reports at runtime.
273
+ pyproject declares `version` dynamic and hatch-vcs derives it from the git
274
+ tag, so a literal anywhere would be a second source that drifts the moment a
275
+ release is cut — `--version` would then report a version the user does not
276
+ have installed. The old form of this test compared pyproject's static
277
+ version against a literal in __init__; both are gone.
275
278
  """
276
279
 
277
- def test_versions_match(self):
280
+ def test_pyproject_declares_version_dynamic(self):
278
281
  import tomllib
279
282
 
280
283
  pyproject = Path(__file__).parent.parent / "pyproject.toml"
281
- declared = tomllib.loads(pyproject.read_text())["project"]["version"]
284
+ project = tomllib.loads(pyproject.read_text())["project"]
282
285
 
286
+ assert "version" not in project, "pyproject declares a static version; the git tag is the only source"
287
+ assert "version" in project.get("dynamic", [])
288
+
289
+ def test_version_is_derived_from_metadata(self):
290
+ """A literal fallback inside `except PackageNotFoundError` is fine.
291
+
292
+ What must not exist is a module-level literal that shadows the derived
293
+ value — that is the second source of truth this test guards against.
294
+ """
283
295
  tree = ast.parse((SRC / "__init__.py").read_text())
284
- runtime = None
285
- for node in ast.walk(tree):
296
+
297
+ calls = [
298
+ n
299
+ for n in ast.walk(tree)
300
+ if isinstance(n, ast.Call) and isinstance(n.func, ast.Name) and n.func.id.endswith("metadata_version")
301
+ ]
302
+ assert calls, "__version__ is not derived from installed metadata"
303
+
304
+ for node in tree.body: # module level only; the except-branch is nested
286
305
  if isinstance(node, ast.Assign):
287
306
  for target in node.targets:
288
307
  if isinstance(target, ast.Name) and target.id == "__version__":
289
- if isinstance(node.value, ast.Constant):
290
- runtime = node.value.value
308
+ assert not isinstance(node.value, ast.Constant), (
309
+ "__version__ is assigned a literal at module level"
310
+ )
311
+
312
+ def test_runtime_version_matches_installed_metadata(self):
313
+ from importlib.metadata import version
314
+
315
+ import secretscreen
291
316
 
292
- assert runtime == declared, f"pyproject version {declared!r} != __version__ {runtime!r}"
317
+ assert secretscreen.__version__ == version("secretscreen")
293
318
 
294
319
 
295
320
  class TestCLIEntryPoint:
@@ -4,6 +4,7 @@ from secretscreen import Finding, Mode, audit_dict, audit_pair, redact_dict, red
4
4
  from secretscreen._core import (
5
5
  _MAX_DETECT_LENGTH,
6
6
  _MAX_RECURSIVE_DEPTH,
7
+ REDACTED,
7
8
  STATE_REDACTED,
8
9
  STATE_UNSCANNED,
9
10
  explain_dict,
@@ -384,11 +385,19 @@ class TestSecurityFixes:
384
385
  finding_str = str(finding)
385
386
  assert "sup3r_s3cr3t" not in finding_str
386
387
 
387
- def test_large_value_does_not_cause_dos(self) -> None:
388
- """MEDIUM-3: Values over 1MB skip the value-scanning layers."""
388
+ def test_large_value_skips_the_scanning_layers(self) -> None:
389
+ """MEDIUM-3: values past the cap are never scanned, so they are not a DoS.
390
+
391
+ The size cap still holds — layers 2-5 do not run. What changed is what
392
+ happens afterwards: an unexamined value is redacted rather than returned,
393
+ because returning it claims a screening that did not happen.
394
+ """
389
395
  large_value = "x" * 2_000_000 # 2MB
390
- result = redact_pair("SOME_KEY", large_value)
391
- assert result == large_value # returned unchanged, not processed
396
+ assert redact_pair("SOME_KEY", large_value) == REDACTED
397
+
398
+ finding = audit_pair("SOME_KEY", large_value)
399
+ assert finding is not None
400
+ assert finding.layer == "size_cap" # not format/entropy — nothing scanned it
392
401
 
393
402
  def test_large_value_under_secret_key_is_still_redacted(self) -> None:
394
403
  """The size cap must not fail open: layer 1 reads the key, not the value.
@@ -444,22 +453,51 @@ class TestSecurityFixes:
444
453
  assert redact_pair("SECRET_KEY", large_value) == "[REDACTED]"
445
454
  assert time.perf_counter() - start < 1.0
446
455
 
447
- def test_oversized_value_under_non_denylisted_key_is_a_known_gap(self) -> None:
448
- """Documents the residual size-cap gap rather than leaving it unstated.
456
+ def test_oversized_value_under_an_innocuous_key_fails_closed(self) -> None:
457
+ """The former residual gap, now closed.
449
458
 
450
459
  Keys like DATABASE_URL carry a safe suffix ('_url'), so layer 1 never
451
- matches them — they rely on layer 4, which scans the value and is
452
- therefore skipped when oversized. Such values pass through unredacted.
453
- Callers that print values must surface the skip; see _MAX_DETECT_LENGTH.
460
+ matches them — they rely on layer 4, which scans the value and is skipped
461
+ when oversized. Such values used to pass through unredacted, and the
462
+ contract was that callers "must surface the skip". They could not: the
463
+ state was not exposed, so the CLI re-derived it by hand and a library
464
+ consumer had no way to at all, printing an unexamined secret.
454
465
  """
455
466
  large_url = "postgres://user:pw@host/db?pad=" + "x" * 2_000_000
456
- assert redact_pair("DATABASE_URL", large_url) == large_url
457
- assert audit_pair("DATABASE_URL", large_url) is None
467
+ assert redact_pair("DATABASE_URL", large_url) == REDACTED
458
468
 
459
- # Same URL under the cap is redacted normally.
469
+ finding = audit_pair("DATABASE_URL", large_url)
470
+ assert finding is not None
471
+ assert finding.layer == "size_cap"
472
+ assert "not examined" in (finding.detail or "")
473
+
474
+ # Same URL under the cap is scanned and partially redacted as before.
460
475
  small_url = "postgres://user:pw@host/db"
461
476
  assert redact_pair("DATABASE_URL", small_url) == "postgres://user:REDACTED@host/db"
462
477
 
478
+ def test_a_secret_inside_an_oversized_value_is_not_emitted(self) -> None:
479
+ """The concrete failure this closes.
480
+
481
+ A container env var over the cap, under a key matching no secret
482
+ pattern, carrying a token that only value-shape detection would find.
483
+ Before, the token came back verbatim and audit_pair reported clean.
484
+ """
485
+ token = "ghp_012345678901234567890123456789012345"
486
+ value = "A" * 70_000 + token
487
+
488
+ assert token not in redact_pair("NOTES", value)
489
+ assert audit_pair("NOTES", value) is not None
490
+
491
+ def test_oversized_under_a_secret_key_still_reports_the_real_reason(self) -> None:
492
+ """Layer 1 reads the key, not the value, so it still wins.
493
+
494
+ That distinction matters: redacted-because-a-secret-was-named is a
495
+ different fact from redacted-because-unexaminable.
496
+ """
497
+ finding = audit_pair("PASSWORD", "x" * 2_000_000)
498
+ assert finding is not None
499
+ assert finding.layer == "key_pattern"
500
+
463
501
  def test_deeply_nested_dict_does_not_crash(self) -> None:
464
502
  """MEDIUM-4: redact_dict should handle deeply nested dicts without RecursionError."""
465
503
  data: dict = {}
@@ -1,33 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: pip
4
- directory: /
5
- schedule:
6
- interval: daily
7
- cooldown:
8
- semver-major-days: 30
9
- semver-minor-days: 7
10
- semver-patch-days: 3
11
- groups:
12
- pip-patches:
13
- update-types: ["patch"]
14
- pip-minors:
15
- update-types: ["minor"]
16
- commit-message:
17
- prefix: chore
18
- include: scope
19
- labels:
20
- - dependencies
21
-
22
- - package-ecosystem: github-actions
23
- directory: /
24
- schedule:
25
- interval: weekly
26
- groups:
27
- actions:
28
- patterns: ["*"]
29
- commit-message:
30
- prefix: chore
31
- include: scope
32
- labels:
33
- - dependencies
@@ -1,29 +0,0 @@
1
- name: Dependabot Auto-merge
2
-
3
- on:
4
- pull_request_target:
5
-
6
- permissions:
7
- contents: write
8
- pull-requests: write
9
-
10
- jobs:
11
- automerge:
12
- if: github.actor == 'dependabot[bot]'
13
- runs-on: ubuntu-latest
14
- steps:
15
- - name: Generate token
16
- id: generate_token
17
- uses: actions/create-github-app-token@v3
18
- with:
19
- app-id: ${{ secrets.BOT_APP_ID }}
20
- private-key: ${{ secrets.BOT_PRIVATE_KEY }}
21
- - name: Auto-approve PR
22
- uses: hmarr/auto-approve-action@b40d6c9ed2fa10c9a2749eca7eb004418a705501
23
- with:
24
- github-token: ${{ steps.generate_token.outputs.token }}
25
- - name: Enable auto-merge
26
- run: gh pr merge --auto --rebase "$PR_URL"
27
- env:
28
- PR_URL: ${{ github.event.pull_request.html_url }}
29
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
File without changes
File without changes
File without changes
File without changes