guardana-report 0.1.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.
- guardana_report-0.1.0/.gitignore +37 -0
- guardana_report-0.1.0/LICENSE +202 -0
- guardana_report-0.1.0/PKG-INFO +39 -0
- guardana_report-0.1.0/README.md +13 -0
- guardana_report-0.1.0/pyproject.toml +40 -0
- guardana_report-0.1.0/src/guardana/report/__init__.py +27 -0
- guardana_report-0.1.0/src/guardana/report/base.py +13 -0
- guardana_report-0.1.0/src/guardana/report/human.py +35 -0
- guardana_report-0.1.0/src/guardana/report/json_report.py +24 -0
- guardana_report-0.1.0/src/guardana/report/junit.py +40 -0
- guardana_report-0.1.0/src/guardana/report/py.typed +0 -0
- guardana_report-0.1.0/src/guardana/report/sarif.py +54 -0
- guardana_report-0.1.0/tests/test_junit.py +34 -0
- guardana_report-0.1.0/tests/test_renderers.py +30 -0
- guardana_report-0.1.0/tests/test_sarif.py +26 -0
- guardana_report-0.1.0/tests/test_unverified_rendering.py +58 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.venv/
|
|
4
|
+
.uv/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
*.egg-info/
|
|
8
|
+
**/*.egg-info/
|
|
9
|
+
.mypy_cache/
|
|
10
|
+
.ruff_cache/
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.import_linter_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
.coverage.*
|
|
15
|
+
coverage.xml
|
|
16
|
+
htmlcov/
|
|
17
|
+
.python-version
|
|
18
|
+
|
|
19
|
+
# OS
|
|
20
|
+
.DS_Store
|
|
21
|
+
Thumbs.db
|
|
22
|
+
|
|
23
|
+
# Env / secrets
|
|
24
|
+
.env
|
|
25
|
+
.env.*
|
|
26
|
+
|
|
27
|
+
# Editors
|
|
28
|
+
.vscode/
|
|
29
|
+
.idea/
|
|
30
|
+
|
|
31
|
+
# Logs
|
|
32
|
+
*.log
|
|
33
|
+
|
|
34
|
+
# AI-agent tooling and internal working docs (not part of the published project)
|
|
35
|
+
.claude/
|
|
36
|
+
docs/superpowers/
|
|
37
|
+
.playwright-mcp/
|
|
@@ -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 2026 Guardana contributors
|
|
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,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: guardana-report
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Guardana renderers: human, SARIF, JSON, and JUnit output.
|
|
5
|
+
Project-URL: Homepage, https://guardana.io
|
|
6
|
+
Project-URL: Repository, https://github.com/guardana/guardana
|
|
7
|
+
Project-URL: Documentation, https://guardana.dev
|
|
8
|
+
Project-URL: Issues, https://github.com/guardana/guardana/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/guardana/guardana/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Guardana contributors <maintainers@guardana.io>
|
|
11
|
+
Maintainer-email: Guardana contributors <maintainers@guardana.io>
|
|
12
|
+
License-Expression: Apache-2.0
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: ai-security,llm,mlsecops,prompt-injection,security-scanner
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: guardana-core<0.2,>=0.1.0
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# guardana-report
|
|
28
|
+
|
|
29
|
+
Guardana report renderers — human, SARIF, JSON, JUnit.
|
|
30
|
+
|
|
31
|
+
Part of **[Guardana](https://github.com/guardana/guardana)** — security
|
|
32
|
+
verification for self-hosted and self-built AI (model files, live endpoints,
|
|
33
|
+
and agents) from one rule engine that runs on your laptop, in CI, and next to
|
|
34
|
+
a served model.
|
|
35
|
+
|
|
36
|
+
- Main README & quickstart: https://github.com/guardana/guardana#readme
|
|
37
|
+
- Documentation: https://guardana.dev
|
|
38
|
+
|
|
39
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# guardana-report
|
|
2
|
+
|
|
3
|
+
Guardana report renderers — human, SARIF, JSON, JUnit.
|
|
4
|
+
|
|
5
|
+
Part of **[Guardana](https://github.com/guardana/guardana)** — security
|
|
6
|
+
verification for self-hosted and self-built AI (model files, live endpoints,
|
|
7
|
+
and agents) from one rule engine that runs on your laptop, in CI, and next to
|
|
8
|
+
a served model.
|
|
9
|
+
|
|
10
|
+
- Main README & quickstart: https://github.com/guardana/guardana#readme
|
|
11
|
+
- Documentation: https://guardana.dev
|
|
12
|
+
|
|
13
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "guardana-report"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Guardana renderers: human, SARIF, JSON, and JUnit output."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Guardana contributors", email = "maintainers@guardana.io" },
|
|
11
|
+
]
|
|
12
|
+
maintainers = [
|
|
13
|
+
{ name = "Guardana contributors", email = "maintainers@guardana.io" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["ai-security", "llm", "prompt-injection", "security-scanner", "mlsecops"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"License :: OSI Approved :: Apache Software License",
|
|
22
|
+
"Topic :: Security",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = ["guardana-core>=0.1.0,<0.2"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://guardana.io"
|
|
30
|
+
Repository = "https://github.com/guardana/guardana"
|
|
31
|
+
Documentation = "https://guardana.dev"
|
|
32
|
+
Issues = "https://github.com/guardana/guardana/issues"
|
|
33
|
+
Changelog = "https://github.com/guardana/guardana/blob/main/CHANGELOG.md"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/guardana"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from guardana.report.base import Renderer
|
|
2
|
+
from guardana.report.human import HumanRenderer
|
|
3
|
+
from guardana.report.json_report import JsonRenderer
|
|
4
|
+
from guardana.report.junit import JUnitRenderer
|
|
5
|
+
from guardana.report.sarif import SarifRenderer
|
|
6
|
+
|
|
7
|
+
_RENDERERS: dict[str, Renderer] = {
|
|
8
|
+
r.name: r for r in (JsonRenderer(), HumanRenderer(), SarifRenderer(), JUnitRenderer())
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_renderer(name: str) -> Renderer:
|
|
13
|
+
"""Look up a renderer by the name the CLI's `--format` takes."""
|
|
14
|
+
try:
|
|
15
|
+
return _RENDERERS[name]
|
|
16
|
+
except KeyError as exc:
|
|
17
|
+
raise ValueError(f"unknown renderer: {name!r}") from exc
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"HumanRenderer",
|
|
22
|
+
"JUnitRenderer",
|
|
23
|
+
"JsonRenderer",
|
|
24
|
+
"Renderer",
|
|
25
|
+
"SarifRenderer",
|
|
26
|
+
"get_renderer",
|
|
27
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import Protocol
|
|
2
|
+
|
|
3
|
+
from guardana.core.report import ScanResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Renderer(Protocol):
|
|
7
|
+
"""Turns a `ScanResult` into text. One implementation per output format."""
|
|
8
|
+
|
|
9
|
+
name: str
|
|
10
|
+
|
|
11
|
+
def render(self, result: ScanResult) -> str:
|
|
12
|
+
"""Render one scan result to text."""
|
|
13
|
+
...
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from guardana.core.report import ScanResult
|
|
2
|
+
|
|
3
|
+
_ICON = {"CRITICAL": "✖", "HIGH": "✖", "MEDIUM": "▲", "LOW": "•", "INFO": "·"}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class HumanRenderer:
|
|
7
|
+
"""Terminal output: one line per finding, with a summary."""
|
|
8
|
+
|
|
9
|
+
name = "human"
|
|
10
|
+
|
|
11
|
+
def render(self, result: ScanResult) -> str:
|
|
12
|
+
"""Render one scan result to text."""
|
|
13
|
+
lines = []
|
|
14
|
+
for f in result.findings:
|
|
15
|
+
icon = _ICON.get(f.severity.name, "•")
|
|
16
|
+
lines.append(f"{icon} [{f.severity.name}] {f.rule_id} — {f.title}")
|
|
17
|
+
lines.append(f" {f.evidence.summary} ({f.target_ref})")
|
|
18
|
+
if not result.findings:
|
|
19
|
+
if result.rules_run == 0:
|
|
20
|
+
lines.append("⚠ 0 rules ran — nothing was checked (this is not an all-clear).")
|
|
21
|
+
else:
|
|
22
|
+
lines.append("✓ No findings.")
|
|
23
|
+
for f in result.unverified:
|
|
24
|
+
reason = f.verdict.rationale if f.verdict is not None else f.evidence.summary
|
|
25
|
+
lines.append(f"? [UNVERIFIED] {f.rule_id} — {f.title}")
|
|
26
|
+
lines.append(f" {reason} ({f.target_ref})")
|
|
27
|
+
lines.append("")
|
|
28
|
+
summary = (
|
|
29
|
+
f"{len(result.findings)} finding(s); "
|
|
30
|
+
f"{result.rules_run} rule(s) run, {len(result.rules_skipped)} skipped."
|
|
31
|
+
)
|
|
32
|
+
if result.unverified:
|
|
33
|
+
summary += f" {len(result.unverified)} unverified."
|
|
34
|
+
lines.append(summary)
|
|
35
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from guardana.core.report import ScanResult, finding_to_dict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class JsonRenderer:
|
|
7
|
+
"""Machine-readable output: the canonical Finding shape, verdicts included."""
|
|
8
|
+
|
|
9
|
+
name = "json"
|
|
10
|
+
|
|
11
|
+
def render(self, result: ScanResult) -> str:
|
|
12
|
+
"""Render one scan result to text."""
|
|
13
|
+
max_sev = result.max_severity()
|
|
14
|
+
payload = {
|
|
15
|
+
"findings": [finding_to_dict(f) for f in result.findings],
|
|
16
|
+
"unverified": [finding_to_dict(f) for f in result.unverified],
|
|
17
|
+
"summary": {
|
|
18
|
+
"rules_run": result.rules_run,
|
|
19
|
+
"rules_skipped": list(result.rules_skipped),
|
|
20
|
+
"unverified": len(result.unverified),
|
|
21
|
+
"max_severity": max_sev.name if max_sev else None,
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
return json.dumps(payload, indent=2)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from xml.sax.saxutils import escape, quoteattr
|
|
2
|
+
|
|
3
|
+
from guardana.core.report import ScanResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class JUnitRenderer:
|
|
7
|
+
"""JUnit XML — what most CI systems render as a test report."""
|
|
8
|
+
|
|
9
|
+
name = "junit"
|
|
10
|
+
|
|
11
|
+
def render(self, result: ScanResult) -> str:
|
|
12
|
+
"""Render one scan result to text."""
|
|
13
|
+
cases = []
|
|
14
|
+
for f in result.findings:
|
|
15
|
+
name = quoteattr(f.rule_id)
|
|
16
|
+
classname = quoteattr(f.target_ref)
|
|
17
|
+
message = quoteattr(f.title)
|
|
18
|
+
summary = escape(f.evidence.summary)
|
|
19
|
+
cases.append(
|
|
20
|
+
f" <testcase name={name} classname={classname}>\n"
|
|
21
|
+
f" <failure message={message}>{summary}</failure>\n"
|
|
22
|
+
f" </testcase>"
|
|
23
|
+
)
|
|
24
|
+
for f in result.unverified:
|
|
25
|
+
name = quoteattr(f.rule_id)
|
|
26
|
+
classname = quoteattr(f.target_ref)
|
|
27
|
+
message = quoteattr(f.title)
|
|
28
|
+
reason = escape(f.verdict.rationale if f.verdict is not None else f.evidence.summary)
|
|
29
|
+
cases.append(
|
|
30
|
+
f" <testcase name={name} classname={classname}>\n"
|
|
31
|
+
f" <skipped message={message}>{reason}</skipped>\n"
|
|
32
|
+
f" </testcase>"
|
|
33
|
+
)
|
|
34
|
+
body = "\n".join(cases)
|
|
35
|
+
return (
|
|
36
|
+
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
37
|
+
f'<testsuite name="guardana" tests="{result.rules_run}" '
|
|
38
|
+
f'failures="{len(result.findings)}" skipped="{len(result.unverified)}">\n'
|
|
39
|
+
f"{body}\n</testsuite>"
|
|
40
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from guardana.core.report import Finding, ScanResult
|
|
4
|
+
from guardana.core.severity import Severity
|
|
5
|
+
|
|
6
|
+
_LEVEL = {
|
|
7
|
+
Severity.CRITICAL: "error",
|
|
8
|
+
Severity.HIGH: "error",
|
|
9
|
+
Severity.MEDIUM: "warning",
|
|
10
|
+
Severity.LOW: "note",
|
|
11
|
+
Severity.INFO: "note",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _sarif_result(f: Finding, *, level: str, kind: str | None = None) -> dict[str, object]:
|
|
16
|
+
result: dict[str, object] = {
|
|
17
|
+
"ruleId": f.rule_id,
|
|
18
|
+
"level": level,
|
|
19
|
+
"message": {"text": f"{f.title}: {f.evidence.summary}"},
|
|
20
|
+
"locations": [{"physicalLocation": {"artifactLocation": {"uri": f.target_ref}}}],
|
|
21
|
+
}
|
|
22
|
+
if kind is not None:
|
|
23
|
+
result["kind"] = kind
|
|
24
|
+
return result
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _results(result: ScanResult) -> list[dict[str, object]]:
|
|
28
|
+
confirmed = [_sarif_result(f, level=_LEVEL.get(f.severity, "note")) for f in result.findings]
|
|
29
|
+
# An unverified check is not a clean pass: surface it as a note flagged for
|
|
30
|
+
# review, never omit it (that would read as "no problem" to a SARIF consumer).
|
|
31
|
+
unverified = [_sarif_result(f, level="note", kind="review") for f in result.unverified]
|
|
32
|
+
return confirmed + unverified
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SarifRenderer:
|
|
36
|
+
"""SARIF 2.1.0 — what GitHub code scanning ingests."""
|
|
37
|
+
|
|
38
|
+
name = "sarif"
|
|
39
|
+
|
|
40
|
+
def render(self, result: ScanResult) -> str:
|
|
41
|
+
"""Render one scan result to text."""
|
|
42
|
+
doc = {
|
|
43
|
+
"version": "2.1.0",
|
|
44
|
+
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
|
45
|
+
"runs": [
|
|
46
|
+
{
|
|
47
|
+
"tool": {
|
|
48
|
+
"driver": {"name": "Guardana", "informationUri": "https://guardana.dev"}
|
|
49
|
+
},
|
|
50
|
+
"results": _results(result),
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
}
|
|
54
|
+
return json.dumps(doc, indent=2)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import defusedxml.minidom
|
|
2
|
+
from guardana.core.report import Evidence, Finding, ScanResult
|
|
3
|
+
from guardana.core.severity import Severity
|
|
4
|
+
from guardana.report import get_renderer
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_junit_escapes_quotes_no_injection() -> None:
|
|
8
|
+
"""Test that JUnit renderer prevents XML injection via unescaped quotes in attributes."""
|
|
9
|
+
malicious_rule_id = 'x" evil="yes'
|
|
10
|
+
f = Finding(
|
|
11
|
+
malicious_rule_id,
|
|
12
|
+
Severity.HIGH,
|
|
13
|
+
"Test finding",
|
|
14
|
+
(),
|
|
15
|
+
"target.py",
|
|
16
|
+
Evidence(summary="Test evidence"),
|
|
17
|
+
)
|
|
18
|
+
result = ScanResult((f,), 1, ())
|
|
19
|
+
renderer = get_renderer("junit")
|
|
20
|
+
output = renderer.render(result)
|
|
21
|
+
|
|
22
|
+
# Parse the XML to ensure it's valid (no injection breaks the structure)
|
|
23
|
+
doc = defusedxml.minidom.parseString(output)
|
|
24
|
+
|
|
25
|
+
# Extract the testcase element and verify the name attribute was escaped
|
|
26
|
+
testcases = doc.getElementsByTagName("testcase")
|
|
27
|
+
assert len(testcases) == 1
|
|
28
|
+
testcase = testcases[0]
|
|
29
|
+
|
|
30
|
+
# The name attribute should equal the original malicious string, proving it was
|
|
31
|
+
# treated as data (escaped) rather than interpreted as markup
|
|
32
|
+
assert testcase.getAttribute("name") == malicious_rule_id
|
|
33
|
+
# Ensure the injected 'evil' attribute was NOT added
|
|
34
|
+
assert not testcase.hasAttribute("evil")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from guardana.core.report import Evidence, Finding, ScanResult
|
|
4
|
+
from guardana.core.severity import Severity
|
|
5
|
+
from guardana.report import get_renderer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _result() -> ScanResult:
|
|
9
|
+
f = Finding(
|
|
10
|
+
"guardana.sc.pickle",
|
|
11
|
+
Severity.CRITICAL,
|
|
12
|
+
"Dangerous pickle opcode",
|
|
13
|
+
(),
|
|
14
|
+
"model.pkl",
|
|
15
|
+
Evidence(summary="REDUCE calls os.system"),
|
|
16
|
+
)
|
|
17
|
+
return ScanResult((f,), rules_run=1, rules_skipped=())
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_json_renderer_is_machine_readable() -> None:
|
|
21
|
+
out = json.loads(get_renderer("json").render(_result()))
|
|
22
|
+
assert out["findings"][0]["rule_id"] == "guardana.sc.pickle"
|
|
23
|
+
assert out["findings"][0]["severity"] == "CRITICAL"
|
|
24
|
+
assert out["summary"]["rules_run"] == 1
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_human_renderer_mentions_rule_and_severity() -> None:
|
|
28
|
+
out = get_renderer("human").render(_result())
|
|
29
|
+
assert "guardana.sc.pickle" in out
|
|
30
|
+
assert "CRITICAL" in out
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from guardana.core.report import Evidence, Finding, ScanResult
|
|
4
|
+
from guardana.core.severity import Severity
|
|
5
|
+
from guardana.report import get_renderer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _result() -> ScanResult:
|
|
9
|
+
f = Finding(
|
|
10
|
+
"guardana.sc.pickle",
|
|
11
|
+
Severity.HIGH,
|
|
12
|
+
"Dangerous opcode",
|
|
13
|
+
(),
|
|
14
|
+
"model.pkl",
|
|
15
|
+
Evidence(summary="REDUCE"),
|
|
16
|
+
)
|
|
17
|
+
return ScanResult((f,), 1, ())
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_sarif_is_valid_2_1_0_shape() -> None:
|
|
21
|
+
doc = json.loads(get_renderer("sarif").render(_result()))
|
|
22
|
+
assert doc["version"] == "2.1.0"
|
|
23
|
+
run = doc["runs"][0]
|
|
24
|
+
assert run["tool"]["driver"]["name"] == "Guardana"
|
|
25
|
+
assert run["results"][0]["level"] == "error"
|
|
26
|
+
assert run["results"][0]["ruleId"] == "guardana.sc.pickle"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""An unverified check (ran, but could not reach a verdict) must be visible and
|
|
2
|
+
distinct in every output format — never dropped, never rendered as a confirmed
|
|
3
|
+
finding. That silent-drop would read as a clean pass to whatever consumes the
|
|
4
|
+
report."""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
from guardana.core.evaluator.base import Verdict
|
|
9
|
+
from guardana.core.report.finding import Evidence, Finding
|
|
10
|
+
from guardana.core.report.result import ScanResult
|
|
11
|
+
from guardana.core.severity import Severity
|
|
12
|
+
from guardana.report import get_renderer
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _unverified_result() -> ScanResult:
|
|
16
|
+
finding = Finding(
|
|
17
|
+
rule_id="guardana.prompt.judge.demo",
|
|
18
|
+
severity=Severity.HIGH,
|
|
19
|
+
title="Judged jailbreak",
|
|
20
|
+
taxonomy=(),
|
|
21
|
+
target_ref="http://x#m",
|
|
22
|
+
evidence=Evidence(summary="grading did not complete"),
|
|
23
|
+
verdict=Verdict("inconclusive", 0.0, "judge endpoint unreachable", "llm_judge@2025.1"),
|
|
24
|
+
)
|
|
25
|
+
return ScanResult(findings=(), rules_run=1, rules_skipped=(), unverified=(finding,))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_human_surfaces_unverified_distinctly() -> None:
|
|
29
|
+
out = get_renderer("human").render(_unverified_result())
|
|
30
|
+
assert "UNVERIFIED" in out
|
|
31
|
+
assert "judge endpoint unreachable" in out
|
|
32
|
+
assert "0 finding(s)" in out
|
|
33
|
+
assert "1 unverified" in out
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_json_lists_unverified_separately() -> None:
|
|
37
|
+
payload = json.loads(get_renderer("json").render(_unverified_result()))
|
|
38
|
+
assert payload["findings"] == []
|
|
39
|
+
assert len(payload["unverified"]) == 1
|
|
40
|
+
assert payload["unverified"][0]["verdict"]["outcome"] == "inconclusive"
|
|
41
|
+
assert payload["summary"]["unverified"] == 1
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_sarif_marks_unverified_as_review_note() -> None:
|
|
45
|
+
doc = json.loads(get_renderer("sarif").render(_unverified_result()))
|
|
46
|
+
results = doc["runs"][0]["results"]
|
|
47
|
+
assert len(results) == 1
|
|
48
|
+
assert results[0]["level"] == "note"
|
|
49
|
+
assert results[0]["kind"] == "review"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_junit_marks_unverified_as_skipped_not_failure() -> None:
|
|
53
|
+
xml = get_renderer("junit").render(_unverified_result())
|
|
54
|
+
assert 'failures="0"' in xml
|
|
55
|
+
assert 'skipped="1"' in xml
|
|
56
|
+
assert "<skipped " in xml
|
|
57
|
+
assert "<failure" not in xml
|
|
58
|
+
assert "judge endpoint unreachable" in xml
|