granttrace 2.4.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 (66) hide show
  1. granttrace-2.4.0/CHANGELOG.md +151 -0
  2. granttrace-2.4.0/CONTRIBUTING.md +47 -0
  3. granttrace-2.4.0/LICENSE +202 -0
  4. granttrace-2.4.0/MANIFEST.in +8 -0
  5. granttrace-2.4.0/PKG-INFO +108 -0
  6. granttrace-2.4.0/README.md +81 -0
  7. granttrace-2.4.0/SECURITY.md +59 -0
  8. granttrace-2.4.0/VERIFICATION.md +315 -0
  9. granttrace-2.4.0/api_sentinel.py +402 -0
  10. granttrace-2.4.0/config.example.json +69 -0
  11. granttrace-2.4.0/config.schema.json +243 -0
  12. granttrace-2.4.0/core/__init__.py +4 -0
  13. granttrace-2.4.0/core/auditor.py +1101 -0
  14. granttrace-2.4.0/core/config_scaffold.py +254 -0
  15. granttrace-2.4.0/core/config_validator.py +1408 -0
  16. granttrace-2.4.0/core/diff.py +839 -0
  17. granttrace-2.4.0/core/evidence.py +353 -0
  18. granttrace-2.4.0/core/generator.py +1048 -0
  19. granttrace-2.4.0/core/models.py +104 -0
  20. granttrace-2.4.0/core/parameters.py +198 -0
  21. granttrace-2.4.0/core/parser.py +495 -0
  22. granttrace-2.4.0/core/reporter.py +359 -0
  23. granttrace-2.4.0/core/transactions.py +167 -0
  24. granttrace-2.4.0/docs/advanced.md +59 -0
  25. granttrace-2.4.0/docs/assets/report-preview.png +0 -0
  26. granttrace-2.4.0/docs/business-scenarios.md +18 -0
  27. granttrace-2.4.0/docs/configuration.md +104 -0
  28. granttrace-2.4.0/docs/parameter-serialization.md +19 -0
  29. granttrace-2.4.0/docs/release-checklist.md +74 -0
  30. granttrace-2.4.0/examples/README.md +34 -0
  31. granttrace-2.4.0/examples/sample_report.html +659 -0
  32. granttrace-2.4.0/examples/sample_result.json +583 -0
  33. granttrace-2.4.0/granttrace.egg-info/PKG-INFO +108 -0
  34. granttrace-2.4.0/granttrace.egg-info/SOURCES.txt +64 -0
  35. granttrace-2.4.0/granttrace.egg-info/dependency_links.txt +1 -0
  36. granttrace-2.4.0/granttrace.egg-info/entry_points.txt +2 -0
  37. granttrace-2.4.0/granttrace.egg-info/requires.txt +8 -0
  38. granttrace-2.4.0/granttrace.egg-info/top_level.txt +3 -0
  39. granttrace-2.4.0/mock_server/__init__.py +4 -0
  40. granttrace-2.4.0/mock_server/server.py +190 -0
  41. granttrace-2.4.0/openapi.json +180 -0
  42. granttrace-2.4.0/pyproject.toml +72 -0
  43. granttrace-2.4.0/scripts/verify_business_scenarios.py +216 -0
  44. granttrace-2.4.0/scripts/verify_examples.py +163 -0
  45. granttrace-2.4.0/scripts/verify_install.py +271 -0
  46. granttrace-2.4.0/setup.cfg +4 -0
  47. granttrace-2.4.0/test_suite.py +18 -0
  48. granttrace-2.4.0/tests/test_auditor_integration.py +270 -0
  49. granttrace-2.4.0/tests/test_business_authorization.py +100 -0
  50. granttrace-2.4.0/tests/test_config_scaffold.py +197 -0
  51. granttrace-2.4.0/tests/test_config_validation.py +285 -0
  52. granttrace-2.4.0/tests/test_diff.py +209 -0
  53. granttrace-2.4.0/tests/test_diff_hardening.py +178 -0
  54. granttrace-2.4.0/tests/test_evidence.py +167 -0
  55. granttrace-2.4.0/tests/test_parameter_serialization.py +230 -0
  56. granttrace-2.4.0/tests/test_parser_generator_hardening.py +257 -0
  57. granttrace-2.4.0/tests/test_rc2_security_hardening.py +395 -0
  58. granttrace-2.4.0/tests/test_rc3_hardening.py +314 -0
  59. granttrace-2.4.0/tests/test_release_bola.py +146 -0
  60. granttrace-2.4.0/tests/test_release_config.py +234 -0
  61. granttrace-2.4.0/tests/test_release_evidence.py +157 -0
  62. granttrace-2.4.0/tests/test_release_identity.py +86 -0
  63. granttrace-2.4.0/tests/test_release_transactions.py +130 -0
  64. granttrace-2.4.0/tests/test_report_usability.py +201 -0
  65. granttrace-2.4.0/tests/test_schema_regressions.py +210 -0
  66. granttrace-2.4.0/tests/test_v22_auditor_hardening.py +421 -0
@@ -0,0 +1,151 @@
1
+ # Changelog
2
+
3
+ ## 2.4.0 - 2026-10-03
4
+
5
+ ### Added
6
+
7
+ - Generate offline OpenAPI configuration drafts and missing-input checklists;
8
+ reject unresolved drafts and refuse to overwrite existing files.
9
+ - Add offline HTML report search/status filters and compact severity labels.
10
+ - Support strict OpenAPI style/explode and Swagger collectionFormat parameter
11
+ serialization in scans/readbacks, including arrays and lowercase booleans;
12
+ decline unsupported or ambiguous formats before sending requests.
13
+ - Add explicit per-pair expected_visitor_access for legitimate sharing/admin
14
+ reads, recorded as AUTHORIZED, and six local authorization truth fixtures with
15
+ false-positive/false-negative accounting.
16
+ - Add mandatory Ruff checks, real unittest branch coverage with text/XML/JSON
17
+ evidence, runtime dependency auditing with pip-audit, and a Python CodeQL
18
+ workflow. Keep mypy advisory while recording existing type debt.
19
+ - Add simple issue templates and contribution guidance with private vulnerability
20
+ reporting and reminders to exclude credentials and sensitive target data.
21
+
22
+ ### Changed
23
+
24
+ - Promote the previously identified 2.4.0.dev0 development build to 2.4.0 across
25
+ runtime, package metadata and reports; retain api_sentinel.py and
26
+ APISentinelAuditor compatibility.
27
+ - Use granttrace_report.html when no output path is supplied and align package
28
+ description, version status and GrantTrace branding.
29
+ - Keep a concise five-minute README walkthrough, add identity/readback/restoration
30
+ highlights, and preserve the visible report preview and detailed guide links.
31
+ - Explain identity/resource access, changed fields, restoration and next steps
32
+ before raw evidence. JSON report schema is version 2.
33
+ - Remove tests' dependence on untracked config.json; automate JSON/YAML mock
34
+ restoration and clean wheel installation outside the checkout in CI.
35
+ - Maintain reproducible release verification and local-output ignore rules;
36
+ remove an unused demo image while preserving the report preview.
37
+ - Include example configuration, guides and verification scripts in the source
38
+ distribution so its documented local checks can be reproduced.
39
+
40
+ ### Security / Safety
41
+
42
+ - Preserve default read-only auditing and explicit allowlisted JSON PATCH checks;
43
+ active POST/PUT checks and automated authentication are not added.
44
+ - Preserve independent GET readback, original-state snapshots, finally-protected
45
+ restoration and rollback verification. Failed recovery halts subsequent writes.
46
+ - Preserve TLS verification by default, explicit non-loopback HTTP opt-in and
47
+ minimized/redacted evidence by default.
48
+ - Retain denial, anonymous-leak and invalid-baseline boundaries without changing
49
+ the BOLA / IDOR or Mass Assignment detection criteria during release preparation.
50
+
51
+ Historical release tags and assets, including v2.3.1, remain unchanged.
52
+
53
+ ## 2.3.1 - Verified authorization, snapshot and credential fixes
54
+
55
+ - Require trustworthy, clean anonymous rejection before a visitor-denial branch
56
+ can produce endpoint-level SECURE; leaked business data remains suspicious.
57
+ - Reject non-standard JSON constants and overflowing floats in response parsing.
58
+ Validate the original snapshot and finite request payloads before any PATCH;
59
+ preserve recovery when a post-write readback is invalid.
60
+ - Redact component values from request Cookie headers, including names such as
61
+ path/domain/secure/version, quoted/encoded echoes and known numeric credentials.
62
+ - Align readback parameter arrays, elements and override mappings between the
63
+ editor schema, semantic validator and runtime.
64
+ - Load the same JSON/YAML specification authentication context in configuration
65
+ validation and scanning; reject explicit invalid specifications cleanly.
66
+ - Validate the effective CLI write allowlist against its own readback mappings.
67
+ - Add 45 regression tests across four release modules; all 223 tests pass with
68
+ real PyYAML installed. Repeat complete CLI mock audits for JSON and YAML and
69
+ confirm full database restoration.
70
+ - Build/install the 2.3.1 wheel and smoke-test its installed console entry point;
71
+ refresh sample reports and record current verification separately from history.
72
+
73
+ ## 2.3.0 (v2.3.0-final) - Configuration validation, authoritative identity rules, and release hardening
74
+
75
+ - **Authoritative Configuration Validator (`core/config_validator.py`)**:
76
+ - Implemented offline semantic validation engine for `config.json` without external network requests.
77
+ - Added `--validate-config` CLI flag for pre-flight validation (exit code 0 for valid, 2 for invalid), without target-network requests or state-changing target actions.
78
+ - Normal CLI scanning automatically runs the authoritative preflight check, rejecting invalid configurations before creating the auditor or sending any HTTP requests.
79
+ - Enforced single canonical format for operation keys (`<METHOD> /<path>` with strictly single space), consistent case handling, and spelling error suggestions (Levenshtein distance).
80
+ - Implemented symmetric two-way path collision detection (`paths_collide`) between `ignore_readback_paths` and written/readback paths across both validator and transaction rollback.
81
+ - Unified authentication header recognition rules between Validator and Auditor, standardizing `session`, `credential`, custom `auth_header_names`, and OpenAPI-declared security schemes.
82
+
83
+ - **Schema and Exemplary Assets**:
84
+ - Added standard `config.schema.json` (JSON Schema Draft-07) for editor autocomplete, hover documentation, and structural validation.
85
+ - Added comprehensive `config.example.json` with `$schema` linkage, sample identities, readbacks, and BOLA policies.
86
+
87
+ - **Security and Robustness Hardening**:
88
+ - Bound recursion depth (`MAX_RECURSION_DEPTH = 15`) and explicitly reject non-standard JSON numeric values (`NaN`, `Infinity`).
89
+ - Strict credential sanitization across all diagnostic outputs (`Actual`, `Expected`, errors) and stripped CR/LF/control characters to mitigate known log-injection paths.
90
+
91
+ - **Core Detection Behavior Compatibility**:
92
+ - No intentional behavior changes were made to BOLA decisions, snapshot recovery, diff, generator, or parser logic in this release; all existing regression tests continue to pass.
93
+
94
+ - **Test Suite Expansion**:
95
+ - Total automated tests expanded from 118 to 178 (all 178 passing, 0 failures, 0 errors).
96
+ - Added 22 offline configuration validation tests (`tests/test_config_validation.py`).
97
+ - Added 20 security and sanitization tests (`tests/test_rc2_security_hardening.py`).
98
+ - Added 18 strict regression counterexample tests (`tests/test_rc3_hardening.py`).
99
+
100
+ - **Packaging Hygiene and Metadata**:
101
+ - Standardized Python package version in `pyproject.toml` to PEP 440 compliant `2.3.0`, with GitHub / ZIP delivery tag designated as `v2.3.0-final`.
102
+ - Purged all build artifacts, temporary test reports (`API_Security_Report.html`, `result.json`), and caches (`__pycache__`, `*.pyc`, `.pytest_cache`, `.git`) from the distribution archive.
103
+
104
+ ## 2.2.0 - Regression-driven safety fixes
105
+
106
+ - Snapshot/recover complete written fields, objects and arrays using original
107
+ business values; compare the full readback state, including derived changes.
108
+ - Recover after mutation/readback exceptions, guard recovery's own exceptions,
109
+ and stop later writes on failed verification or asynchronous acceptance.
110
+ - Require configured strong readback consistency for unchanged-write SECURE.
111
+ - Do not mistake 403-with-data, historical denial text, anonymous private
112
+ increments, or undeclared public access for access-control enforcement.
113
+ - Compare effective authentication headers; exclude request/trace echoes from
114
+ identity evidence and support explicit trusted response resource_id_paths.
115
+ - Probe readOnly privilege fields while excluding them from ordinary baselines.
116
+ - Recursively validate samples, intersect allOf constraints and reject invalid
117
+ baselines. Resolve 3.1 ref siblings in their original contexts; reject ambiguous
118
+ 3.0/Swagger structural siblings and missing pointers instead of losing fields.
119
+ - Propagate supported media types, rejecting unsupported JSON Patch arrays.
120
+ - Bound/redact bodies, URLs, known credentials, error text and result metadata.
121
+ - Add zero-check CI failure, coverage/suspicious gates, no-network dry-run and
122
+ case-sensitive CLI allowlist replacement.
123
+
124
+ Migration: PUBLIC needs explicit policy; unchanged active checks need strong
125
+ readback consistency. Rewrite 3.0 structural ref siblings as allOf. Full-state
126
+ verification may require explicitly identifying harmless volatile fields. These
127
+ checks do not establish a universal rollback or privacy guarantee.
128
+
129
+ ## 2.1.0 - Safety hardening
130
+
131
+ - Made read-only auditing the default and limited active mutations to explicitly
132
+ allowlisted JSON `PATCH` operations.
133
+ - Added independent read-before/write/read-after/rollback verification, retrying
134
+ readback and treating asynchronous or ambiguous outcomes as errors.
135
+ - Reworked BOLA decisions around owner, cross-visitor, anonymous, and distinct
136
+ visitor-self baselines. Matching JSON structure alone is never confirmation.
137
+ - Added explicit `CONFIRMED`, `SECURE`, `PUBLIC`, `SUSPICIOUS`, `INCONCLUSIVE`,
138
+ `SKIPPED`, and `ERROR` results with honest attempted/conclusive coverage.
139
+ - Enabled TLS verification by default, blocked redirects, capped response sizes,
140
+ added global throttling, and restricted non-loopback clear-text HTTP.
141
+ - Added default evidence minimisation, secret/PII redaction, hashes, and HTML
142
+ escaping.
143
+ - Expanded OpenAPI parsing to JSON/YAML, safe local external references,
144
+ recursive schemas/compositions, and parameter override semantics.
145
+ - Added constraint-aware parameters, valid request baselines, and one-field
146
+ nested mass-assignment mutations.
147
+ - Added packaging metadata, CI, an Apache-2.0 license, security guidance, and a
148
+ standard-library regression suite.
149
+
150
+ The bundled mock remains intentionally vulnerable in one BOLA route and one
151
+ mass-assignment route so the end-to-end flow can be verified safely on loopback.
@@ -0,0 +1,47 @@
1
+ # Contributing to GrantTrace
2
+
3
+ Use Python 3.9 or newer. Create a branch from the latest `main`, then install
4
+ the development dependencies:
5
+
6
+ ```bash
7
+ git switch -c your-change
8
+ python -m pip install -e ".[dev]" "setuptools>=77" wheel
9
+ ```
10
+
11
+ Run the regression suite, local verification scripts and Ruff before opening a PR:
12
+
13
+ ```bash
14
+ python -m unittest discover -s tests
15
+ python scripts/verify_business_scenarios.py
16
+ python scripts/verify_examples.py
17
+ python scripts/verify_install.py
18
+ python -m ruff check .
19
+ ```
20
+
21
+ Measure coverage with the actual regression suite:
22
+
23
+ ```bash
24
+ python -m coverage erase
25
+ python -m coverage run -m unittest discover -s tests
26
+ python -m coverage report
27
+ python -m coverage xml
28
+ python -m coverage json
29
+ ```
30
+
31
+ Mypy is advisory while existing dynamic JSON type issues are tracked:
32
+
33
+ ```bash
34
+ python -m mypy
35
+ ```
36
+
37
+ Keep PRs focused. Explain the problem, the resulting behavior and the checks you
38
+ actually ran. Preserve detection semantics and the write allowlist, independent
39
+ readback and recovery safeguards. Add useful regression cases for changed
40
+ behavior; do not add tests solely to raise the coverage percentage. Use only the
41
+ bundled loopback mock or isolated systems you are explicitly authorized to test.
42
+
43
+ Never commit real tokens, cookies, API keys, account credentials, production data,
44
+ or sensitive identity information. Redact examples and reports before sharing.
45
+ Report vulnerabilities through GitHub's
46
+ [Private Vulnerability Reporting](https://github.com/ysc070528/granttrace/security/advisories/new),
47
+ following [SECURITY.md](SECURITY.md), rather than a public issue.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ include CHANGELOG.md CONTRIBUTING.md SECURITY.md VERIFICATION.md
2
+ include config.example.json config.schema.json openapi.json test_suite.py
3
+ recursive-include scripts *.py
4
+ recursive-include tests *.py
5
+ recursive-include docs *.md
6
+ include docs/assets/report-preview.png
7
+ include examples/README.md examples/sample_report.html examples/sample_result.json
8
+ global-exclude __pycache__ *.py[cod] *.local.json
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: granttrace
3
+ Version: 2.4.0
4
+ Summary: Safety-first OpenAPI authorization auditing tool for BOLA, IDOR and Mass Assignment testing
5
+ Author: GrantTrace contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/ysc070528/granttrace
8
+ Project-URL: Issues, https://github.com/ysc070528/granttrace/issues
9
+ Project-URL: Changelog, https://github.com/ysc070528/granttrace/blob/main/CHANGELOG.md
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Security
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: PyYAML>=6.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=8; extra == "dev"
22
+ Requires-Dist: ruff<1,>=0.6; extra == "dev"
23
+ Requires-Dist: mypy<3,>=1.11; extra == "dev"
24
+ Requires-Dist: coverage[toml]<8,>=7.6; extra == "dev"
25
+ Requires-Dist: types-PyYAML<7,>=6; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # GrantTrace
29
+
30
+ ![CI](https://github.com/ysc070528/granttrace/actions/workflows/test.yml/badge.svg)
31
+ ![Python](https://img.shields.io/badge/python-3.9%2B-blue)
32
+ ![License](https://img.shields.io/badge/license-Apache--2.0-green)
33
+
34
+ **Stable:** [v2.4.0](https://github.com/ysc070528/granttrace/releases/tag/v2.4.0)
35
+
36
+ An OpenAPI authorization auditor that compares identities, verifies persisted changes, and reports restoration evidence.
37
+
38
+ 安全优先、证据驱动的 OpenAPI 权限审计工具。检查 BOLA / IDOR 与 Mass Assignment,输出身份对比、持久化变更及恢复核验的 HTML / JSON 报告。默认只读;主动写测试须显式开启并配置允许清单与独立读回。
39
+
40
+ [五分钟体验](#五分钟体验) · [完整示例报告](examples/sample_report.html) · [配置指南](docs/configuration.md) · [命令行与迁移](docs/advanced.md) · [验收记录](VERIFICATION.md) · [发布自检](docs/release-checklist.md)
41
+
42
+ ## 为什么是 GrantTrace / Why GrantTrace
43
+
44
+ - **Compare identities**:比较 Owner / Visitor / Anonymous 等身份访问同一资源的结果。
45
+ - **Verify real side effects**:通过独立读回验证状态是否真正持久化,不只看 HTTP 状态码。
46
+ - **Restore safely**:主动 PATCH 测试使用显式 allowlist、原始状态快照、恢复与恢复验证。
47
+
48
+ <img src="docs/assets/report-preview.png" alt="GrantTrace 报告:身份访问摘要、修复建议和端点筛选" width="900">
49
+
50
+ ## 五分钟体验
51
+
52
+ 需要 Python 3.9+。在终端中克隆、安装并启动本机演示服务:
53
+
54
+ ```bash
55
+ git clone https://github.com/ysc070528/granttrace.git
56
+ cd granttrace
57
+ python -m pip install -e .
58
+ python mock_server/server.py
59
+ ```
60
+
61
+ 另开终端,进入同一目录执行首次只读扫描:
62
+
63
+ ```bash
64
+ granttrace --spec openapi.json --target http://127.0.0.1:8080 --config config.example.json --export-json result.local.json
65
+ ```
66
+
67
+ 用浏览器打开默认生成的 **`granttrace_report.html`**:先查看发现与修复建议,再按状态筛选端点、展开证据。预期结果为 **1 个 CONFIRMED、1 个 PUBLIC、1 个 SECURE、2 个 SKIPPED**,确定性覆盖率 **60%**。两个 PATCH 因默认只读而跳过。JSON 结果写入 `result.local.json`;两个本地产物均由 `.gitignore` 忽略。
68
+
69
+ 在这个可丢弃的本地靶场体验写测试和恢复核验:
70
+
71
+ ```bash
72
+ granttrace --spec openapi.json --target http://127.0.0.1:8080 --config config.example.json --allow-write-tests --export-json result.local.json
73
+ ```
74
+
75
+ 再次打开 **`granttrace_report.html`**。预期 **2 个 CONFIRMED、1 个 PUBLIC、2 个 SECURE**,确定性覆盖率 **100%**,批量赋值发现的 `rollback_verified` 为 `true`。本次扫描更新同名 HTML / JSON 文件;这些结果只属于内置五个演示端点。
76
+
77
+ 完整离线示例:[HTML 报告](examples/sample_report.html)(下载后用浏览器打开)与 [JSON 结果](examples/sample_result.json)。
78
+
79
+ ## 接入自己的 API
80
+
81
+ 先从规范生成配置草稿和待填清单:
82
+
83
+ ```bash
84
+ granttrace --spec your-openapi.yaml --init-config config.local.json
85
+ ```
86
+
87
+ 填写不同的测试账户、各自资源、授权预期和必要读回信息,再按清单移除草稿标记与全部占位值。草稿未完成时会阻止预检、计划与扫描;写允许清单默认为空。
88
+
89
+ ```bash
90
+ granttrace --spec your-openapi.yaml --config config.local.json --validate-config
91
+ granttrace --spec your-openapi.yaml --config config.local.json --dry-run --export-json plan.local.json
92
+ ```
93
+
94
+ 账户、API Key / Cookie、合法共享和管理员访问配置见 [配置指南](docs/configuration.md)。支持的数组、布尔值及 `style` / `explode` 编码见 [参数规则](docs/parameter-serialization.md)。接入实测前请核对 [安全边界](SECURITY.md)。
95
+
96
+ ## 验证与边界
97
+
98
+ ```bash
99
+ python -m unittest discover -s tests
100
+ python scripts/verify_business_scenarios.py
101
+ python scripts/verify_install.py
102
+ ```
103
+
104
+ 测试直接使用仓库中的 `config.example.json`,无需创建本地凭据文件。[业务场景验收](docs/business-scenarios.md) 单独记录团队共享、管理员读取、跨租户拒绝和故意越权的真值、误报与漏报;[验收记录](VERIFICATION.md) 标明实际测试环境和范围。
105
+
106
+ “没有确认漏洞”不等于系统安全。检查覆盖率、错误、可疑和不确定项;显式授权预期只适用于本次身份与资源组合。仅在具备专用测试账户、独立读回和恢复方案的隔离环境启用写测试。远程 `$ref`、GraphQL、gRPC、自动 OAuth / mTLS 登录以及 POST / PUT 主动测试尚未实现。更多规则与迁移说明见 [操作指南](docs/advanced.md)。
107
+
108
+ Apache License 2.0。
@@ -0,0 +1,81 @@
1
+ # GrantTrace
2
+
3
+ ![CI](https://github.com/ysc070528/granttrace/actions/workflows/test.yml/badge.svg)
4
+ ![Python](https://img.shields.io/badge/python-3.9%2B-blue)
5
+ ![License](https://img.shields.io/badge/license-Apache--2.0-green)
6
+
7
+ **Stable:** [v2.4.0](https://github.com/ysc070528/granttrace/releases/tag/v2.4.0)
8
+
9
+ An OpenAPI authorization auditor that compares identities, verifies persisted changes, and reports restoration evidence.
10
+
11
+ 安全优先、证据驱动的 OpenAPI 权限审计工具。检查 BOLA / IDOR 与 Mass Assignment,输出身份对比、持久化变更及恢复核验的 HTML / JSON 报告。默认只读;主动写测试须显式开启并配置允许清单与独立读回。
12
+
13
+ [五分钟体验](#五分钟体验) · [完整示例报告](examples/sample_report.html) · [配置指南](docs/configuration.md) · [命令行与迁移](docs/advanced.md) · [验收记录](VERIFICATION.md) · [发布自检](docs/release-checklist.md)
14
+
15
+ ## 为什么是 GrantTrace / Why GrantTrace
16
+
17
+ - **Compare identities**:比较 Owner / Visitor / Anonymous 等身份访问同一资源的结果。
18
+ - **Verify real side effects**:通过独立读回验证状态是否真正持久化,不只看 HTTP 状态码。
19
+ - **Restore safely**:主动 PATCH 测试使用显式 allowlist、原始状态快照、恢复与恢复验证。
20
+
21
+ <img src="docs/assets/report-preview.png" alt="GrantTrace 报告:身份访问摘要、修复建议和端点筛选" width="900">
22
+
23
+ ## 五分钟体验
24
+
25
+ 需要 Python 3.9+。在终端中克隆、安装并启动本机演示服务:
26
+
27
+ ```bash
28
+ git clone https://github.com/ysc070528/granttrace.git
29
+ cd granttrace
30
+ python -m pip install -e .
31
+ python mock_server/server.py
32
+ ```
33
+
34
+ 另开终端,进入同一目录执行首次只读扫描:
35
+
36
+ ```bash
37
+ granttrace --spec openapi.json --target http://127.0.0.1:8080 --config config.example.json --export-json result.local.json
38
+ ```
39
+
40
+ 用浏览器打开默认生成的 **`granttrace_report.html`**:先查看发现与修复建议,再按状态筛选端点、展开证据。预期结果为 **1 个 CONFIRMED、1 个 PUBLIC、1 个 SECURE、2 个 SKIPPED**,确定性覆盖率 **60%**。两个 PATCH 因默认只读而跳过。JSON 结果写入 `result.local.json`;两个本地产物均由 `.gitignore` 忽略。
41
+
42
+ 在这个可丢弃的本地靶场体验写测试和恢复核验:
43
+
44
+ ```bash
45
+ granttrace --spec openapi.json --target http://127.0.0.1:8080 --config config.example.json --allow-write-tests --export-json result.local.json
46
+ ```
47
+
48
+ 再次打开 **`granttrace_report.html`**。预期 **2 个 CONFIRMED、1 个 PUBLIC、2 个 SECURE**,确定性覆盖率 **100%**,批量赋值发现的 `rollback_verified` 为 `true`。本次扫描更新同名 HTML / JSON 文件;这些结果只属于内置五个演示端点。
49
+
50
+ 完整离线示例:[HTML 报告](examples/sample_report.html)(下载后用浏览器打开)与 [JSON 结果](examples/sample_result.json)。
51
+
52
+ ## 接入自己的 API
53
+
54
+ 先从规范生成配置草稿和待填清单:
55
+
56
+ ```bash
57
+ granttrace --spec your-openapi.yaml --init-config config.local.json
58
+ ```
59
+
60
+ 填写不同的测试账户、各自资源、授权预期和必要读回信息,再按清单移除草稿标记与全部占位值。草稿未完成时会阻止预检、计划与扫描;写允许清单默认为空。
61
+
62
+ ```bash
63
+ granttrace --spec your-openapi.yaml --config config.local.json --validate-config
64
+ granttrace --spec your-openapi.yaml --config config.local.json --dry-run --export-json plan.local.json
65
+ ```
66
+
67
+ 账户、API Key / Cookie、合法共享和管理员访问配置见 [配置指南](docs/configuration.md)。支持的数组、布尔值及 `style` / `explode` 编码见 [参数规则](docs/parameter-serialization.md)。接入实测前请核对 [安全边界](SECURITY.md)。
68
+
69
+ ## 验证与边界
70
+
71
+ ```bash
72
+ python -m unittest discover -s tests
73
+ python scripts/verify_business_scenarios.py
74
+ python scripts/verify_install.py
75
+ ```
76
+
77
+ 测试直接使用仓库中的 `config.example.json`,无需创建本地凭据文件。[业务场景验收](docs/business-scenarios.md) 单独记录团队共享、管理员读取、跨租户拒绝和故意越权的真值、误报与漏报;[验收记录](VERIFICATION.md) 标明实际测试环境和范围。
78
+
79
+ “没有确认漏洞”不等于系统安全。检查覆盖率、错误、可疑和不确定项;显式授权预期只适用于本次身份与资源组合。仅在具备专用测试账户、独立读回和恢复方案的隔离环境启用写测试。远程 `$ref`、GraphQL、gRPC、自动 OAuth / mTLS 登录以及 POST / PUT 主动测试尚未实现。更多规则与迁移说明见 [操作指南](docs/advanced.md)。
80
+
81
+ Apache License 2.0。
@@ -0,0 +1,59 @@
1
+ # Security and safe operation
2
+
3
+ GrantTrace sends requests to the target named on the command line. Use it
4
+ only against systems for which you have explicit authorization.
5
+
6
+ The default mode does not execute mutation checks. `--allow-write-tests`
7
+ enables state-changing PATCH requests and must be limited to disposable test
8
+ data. Every operation must be present in an explicit write allowlist. POST and
9
+ PUT are not mutated automatically because generic compensation and full-state
10
+ restoration cannot be inferred safely. Active checks require a JSON request
11
+ schema plus a configured GET readback endpoint and explicit field mapping. When a
12
+ change is observed, the scanner attempts to restore the original value and
13
+ verifies the restoration. A rollback failure is reported as an error and must
14
+ be investigated immediately.
15
+
16
+ Since version 2.2, GrantTrace snapshots complete written containers and arrays, using observed
17
+ business values instead of generated examples. Every possibly committed mutation
18
+ passes through finally-protected recovery, including decode/readback exceptions.
19
+ Recovery errors or HTTP 202 halt subsequent writes. Verification compares the
20
+ entire readback document, not only payload fields. Explicit ignore_readback_paths
21
+ may exclude known harmless volatile fields, but cannot overlap written snapshots.
22
+ Never ignore privilege/derived-permission fields to make verification pass.
23
+
24
+ This is not a database transaction. Forced termination, concurrent changes,
25
+ late asynchronous work, logs, notifications and state not exposed by readback
26
+ cannot be undone generically. Use disposable, isolated test resources. Only
27
+ declare consistency=strong after checking the actual server/cache behavior;
28
+ unchanged eventual or unspecified readback cannot establish SECURE. Restoration
29
+ verification describes observed state, not a guarantee about all future state.
30
+
31
+ Only object application/json and application/merge-patch+json are implemented.
32
+ JSON Patch arrays, arbitrary vendor JSON and non-restorable Merge Patch null
33
+ object members are not sent. Explicit CLI write selections replace the config
34
+ allowlist; paths are case sensitive. Use --dry-run to inspect local scope without
35
+ target requests. In CI, use --fail-on-error and an appropriate --min-coverage;
36
+ --fail-on-suspicious also gates unresolved findings. Zero-check scans are not
37
+ security passes.
38
+
39
+ TLS certificate verification is enabled by default. Use `--insecure` only for
40
+ an isolated test environment. Plain HTTP is accepted automatically only for
41
+ loopback targets; other HTTP targets require `--allow-http`.
42
+
43
+ Reports contain minimized and redacted evidence by default. The
44
+ `--include-sensitive-evidence` option should be used only when the report will
45
+ be stored with access controls appropriate for the target data.
46
+
47
+ Non-JSON/broken bodies are omitted by default and represented by hashes. URL
48
+ query values, known credentials and common secret fields are sanitized at result
49
+ boundaries. This is not a universal PII detector: arbitrary private free text,
50
+ path identifiers and unrecognized business fields may remain. Treat minimized
51
+ reports as sensitive too.
52
+
53
+ To report a vulnerability in GrantTrace itself, use GitHub's
54
+ [private vulnerability report form](https://github.com/ysc070528/granttrace/security/advisories/new).
55
+ Describe the affected version, reproduction steps, impact, and a minimal
56
+ redacted example. Do not include real credentials or target data. If the form is
57
+ unavailable to your account, ask the owner for a private contact channel without
58
+ disclosing vulnerability details in a public issue.
59
+