guardana-server 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_server-0.1.0/.gitignore +37 -0
- guardana_server-0.1.0/LICENSE +202 -0
- guardana_server-0.1.0/PKG-INFO +58 -0
- guardana_server-0.1.0/README.md +31 -0
- guardana_server-0.1.0/pyproject.toml +45 -0
- guardana_server-0.1.0/src/guardana/server/__init__.py +4 -0
- guardana_server-0.1.0/src/guardana/server/app.py +78 -0
- guardana_server-0.1.0/src/guardana/server/catalog/__init__.py +1 -0
- guardana_server-0.1.0/src/guardana/server/catalog/en.json +105 -0
- guardana_server-0.1.0/src/guardana/server/dashboard.py +293 -0
- guardana_server-0.1.0/src/guardana/server/envelope.py +80 -0
- guardana_server-0.1.0/src/guardana/server/py.typed +0 -0
- guardana_server-0.1.0/src/guardana/server/rule_catalog.py +25 -0
- guardana_server-0.1.0/src/guardana/server/stats.py +162 -0
- guardana_server-0.1.0/src/guardana/server/store.py +93 -0
- guardana_server-0.1.0/tests/test_dashboard.py +77 -0
- guardana_server-0.1.0/tests/test_server.py +233 -0
- guardana_server-0.1.0/tests/test_stats.py +89 -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,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: guardana-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Guardana collector: minimal FastAPI server that ingests and lists findings.
|
|
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: fastapi>=0.115
|
|
25
|
+
Requires-Dist: pydantic>=2.7
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# guardana-server
|
|
29
|
+
|
|
30
|
+
Guardana's optional collector — a minimal FastAPI service that ingests findings
|
|
31
|
+
from many agents and, optionally, serves a read-only monitoring dashboard.
|
|
32
|
+
|
|
33
|
+
Part of **[Guardana](https://github.com/guardana/guardana)** — security
|
|
34
|
+
verification for self-hosted and self-built AI (model files, live endpoints,
|
|
35
|
+
and agents) from one rule engine that runs on your laptop, in CI, and next to
|
|
36
|
+
a served model.
|
|
37
|
+
|
|
38
|
+
## Run it
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# API only (POST/GET /findings, GET /trend):
|
|
42
|
+
uvicorn --factory guardana.server:create_app
|
|
43
|
+
|
|
44
|
+
# With the opt-in dashboard (adds GET / and GET /stats):
|
|
45
|
+
GUARDANA_DASHBOARD=1 uvicorn --factory guardana.server:create_app
|
|
46
|
+
# or, from your own code: create_app(dashboard=True, refresh_seconds=15)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The dashboard is a single self-contained page (no build step, works offline)
|
|
50
|
+
showing severity, per-source/per-rule breakdowns, an activity-over-time trend,
|
|
51
|
+
the `unverified` counter, and a filterable recent-findings table. It is
|
|
52
|
+
**read-only and unauthenticated** — do not expose it to an untrusted network
|
|
53
|
+
(see [SECURITY.md](https://github.com/guardana/guardana/blob/main/SECURITY.md)).
|
|
54
|
+
|
|
55
|
+
- Main README & quickstart: https://github.com/guardana/guardana#readme
|
|
56
|
+
- Documentation: https://guardana.dev
|
|
57
|
+
|
|
58
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# guardana-server
|
|
2
|
+
|
|
3
|
+
Guardana's optional collector — a minimal FastAPI service that ingests findings
|
|
4
|
+
from many agents and, optionally, serves a read-only monitoring dashboard.
|
|
5
|
+
|
|
6
|
+
Part of **[Guardana](https://github.com/guardana/guardana)** — security
|
|
7
|
+
verification for self-hosted and self-built AI (model files, live endpoints,
|
|
8
|
+
and agents) from one rule engine that runs on your laptop, in CI, and next to
|
|
9
|
+
a served model.
|
|
10
|
+
|
|
11
|
+
## Run it
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# API only (POST/GET /findings, GET /trend):
|
|
15
|
+
uvicorn --factory guardana.server:create_app
|
|
16
|
+
|
|
17
|
+
# With the opt-in dashboard (adds GET / and GET /stats):
|
|
18
|
+
GUARDANA_DASHBOARD=1 uvicorn --factory guardana.server:create_app
|
|
19
|
+
# or, from your own code: create_app(dashboard=True, refresh_seconds=15)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The dashboard is a single self-contained page (no build step, works offline)
|
|
23
|
+
showing severity, per-source/per-rule breakdowns, an activity-over-time trend,
|
|
24
|
+
the `unverified` counter, and a filterable recent-findings table. It is
|
|
25
|
+
**read-only and unauthenticated** — do not expose it to an untrusted network
|
|
26
|
+
(see [SECURITY.md](https://github.com/guardana/guardana/blob/main/SECURITY.md)).
|
|
27
|
+
|
|
28
|
+
- Main README & quickstart: https://github.com/guardana/guardana#readme
|
|
29
|
+
- Documentation: https://guardana.dev
|
|
30
|
+
|
|
31
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "guardana-server"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Guardana collector: minimal FastAPI server that ingests and lists findings."
|
|
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 = ["fastapi>=0.115", "pydantic>=2.7"]
|
|
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"]
|
|
41
|
+
|
|
42
|
+
[dependency-groups]
|
|
43
|
+
dev = [
|
|
44
|
+
"httpx>=0.27",
|
|
45
|
+
]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from dataclasses import asdict
|
|
3
|
+
|
|
4
|
+
from fastapi import FastAPI, HTTPException, Query
|
|
5
|
+
from fastapi.responses import HTMLResponse
|
|
6
|
+
from guardana.server.dashboard import render_dashboard
|
|
7
|
+
from guardana.server.envelope import SCHEMA_VERSION, Submission
|
|
8
|
+
from guardana.server.rule_catalog import rule_catalog
|
|
9
|
+
from guardana.server.stats import compute_stats
|
|
10
|
+
from guardana.server.store import InMemoryStore, Store
|
|
11
|
+
|
|
12
|
+
_UNPROCESSABLE = 422
|
|
13
|
+
_TRUTHY = {"1", "true", "yes", "on"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _dashboard_enabled(flag: bool) -> bool:
|
|
17
|
+
"""Whether to mount the dashboard — the `dashboard=` arg, or `GUARDANA_DASHBOARD` env."""
|
|
18
|
+
return flag or os.environ.get("GUARDANA_DASHBOARD", "").strip().lower() in _TRUTHY
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def create_app(
|
|
22
|
+
store: Store | None = None, *, dashboard: bool = False, refresh_seconds: int = 15
|
|
23
|
+
) -> FastAPI:
|
|
24
|
+
"""Build the collector FastAPI app. Ingest/list/trend always; dashboard opt-in.
|
|
25
|
+
|
|
26
|
+
The dashboard (a read-only monitoring page plus its `/stats` data endpoint) is
|
|
27
|
+
off by default; pass `dashboard=True` or set `GUARDANA_DASHBOARD=1` to mount it.
|
|
28
|
+
"""
|
|
29
|
+
active_store: Store = store if store is not None else InMemoryStore()
|
|
30
|
+
app = FastAPI(title="guardana-server")
|
|
31
|
+
|
|
32
|
+
@app.post("/findings")
|
|
33
|
+
def post_findings(submission: Submission) -> dict[str, object]:
|
|
34
|
+
if submission.schema_version != SCHEMA_VERSION:
|
|
35
|
+
raise HTTPException(
|
|
36
|
+
status_code=_UNPROCESSABLE,
|
|
37
|
+
detail=(
|
|
38
|
+
f"unsupported schema_version {submission.schema_version}; "
|
|
39
|
+
f"this collector speaks version {SCHEMA_VERSION}"
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
active_store.add(submission)
|
|
43
|
+
return {"status": "ok", "stored": len(submission.findings)}
|
|
44
|
+
|
|
45
|
+
@app.get("/findings")
|
|
46
|
+
def get_findings(
|
|
47
|
+
source: str | None = Query(default=None),
|
|
48
|
+
limit: int = Query(default=100, ge=1, le=1000),
|
|
49
|
+
) -> list[Submission]:
|
|
50
|
+
# Paginated: an unbounded list could return the entire store (tens of MB)
|
|
51
|
+
# in one response. Newest first, so `limit` returns the most recent.
|
|
52
|
+
return active_store.submissions(source)[-limit:][::-1]
|
|
53
|
+
|
|
54
|
+
@app.get("/trend")
|
|
55
|
+
def get_trend() -> dict[str, int]:
|
|
56
|
+
return active_store.trend()
|
|
57
|
+
|
|
58
|
+
if _dashboard_enabled(dashboard):
|
|
59
|
+
_mount_dashboard(app, active_store, refresh_seconds)
|
|
60
|
+
|
|
61
|
+
return app
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _mount_dashboard(app: FastAPI, store: Store, refresh_seconds: int) -> None:
|
|
65
|
+
"""Add the read-only dashboard page and its aggregated `/stats` data endpoint."""
|
|
66
|
+
page = render_dashboard(refresh_seconds)
|
|
67
|
+
|
|
68
|
+
@app.get("/", response_class=HTMLResponse)
|
|
69
|
+
def dashboard_page() -> str:
|
|
70
|
+
return page
|
|
71
|
+
|
|
72
|
+
@app.get("/stats")
|
|
73
|
+
def get_stats() -> dict[str, object]:
|
|
74
|
+
return asdict(compute_stats(store.records()))
|
|
75
|
+
|
|
76
|
+
@app.get("/catalog")
|
|
77
|
+
def get_catalog() -> dict[str, dict[str, str]]:
|
|
78
|
+
return rule_catalog()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Human-readable descriptions of the built-in rules, for the dashboard."""
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"language": "en",
|
|
3
|
+
"rules": {
|
|
4
|
+
"guardana.supply_chain.pickle_opcode": {
|
|
5
|
+
"name": "Malicious pickle opcode",
|
|
6
|
+
"description": "A pickle file (including one hidden inside a .pt archive) imports a callable that is not on the safe allowlist — arbitrary code that runs the moment the model is loaded. Never load an untrusted pickle; prefer safetensors."
|
|
7
|
+
},
|
|
8
|
+
"guardana.supply_chain.dependency_risk": {
|
|
9
|
+
"name": "Unsafe deserialization sink",
|
|
10
|
+
"description": "Source code calls an unsafe loader on untrusted data — the pickle family (pickle/joblib/dill/pandas.read_pickle), torch.load without weights_only=True, yaml.load with an unsafe Loader, or numpy.load with allow_pickle. Each can execute arbitrary code on load."
|
|
11
|
+
},
|
|
12
|
+
"guardana.supply_chain.remote_code": {
|
|
13
|
+
"name": "Remote code execution on model load",
|
|
14
|
+
"description": "Code enables trust_remote_code=True or calls torch.hub.load — both download and run Python from a remote repo at load time. Today's most common way a downloaded model achieves code execution on your machine."
|
|
15
|
+
},
|
|
16
|
+
"guardana.supply_chain.remote_code_config": {
|
|
17
|
+
"name": "Config requests custom-code execution",
|
|
18
|
+
"description": "A model config.json declares an auto_map / custom_pipelines pointer to custom Python that runs on a trust_remote_code=True load — the on-disk artifact of the RCE. HIGH when the referenced module ships alongside the config."
|
|
19
|
+
},
|
|
20
|
+
"guardana.supply_chain.code_execution": {
|
|
21
|
+
"name": "Dynamic code or shell execution",
|
|
22
|
+
"description": "Source uses a dynamic-code or shell sink — builtin eval/exec, os.system, or subprocess with shell=True. If any of it touches attacker-influenced input, it is a command-injection vector."
|
|
23
|
+
},
|
|
24
|
+
"guardana.supply_chain.insecure_transport": {
|
|
25
|
+
"name": "Insecure model/data transport",
|
|
26
|
+
"description": "TLS certificate verification is disabled (verify=False → man-in-the-middle), or a model/dataset is fetched over plaintext http:// where its bytes can be swapped in transit."
|
|
27
|
+
},
|
|
28
|
+
"guardana.supply_chain.keras_lambda": {
|
|
29
|
+
"name": "Keras Lambda-layer code execution",
|
|
30
|
+
"description": "A Keras model embeds a Lambda layer — arbitrary Python that runs on load_model, no training or inference needed. Escalated when the layer reaches for os/subprocess and similar (CVE-2024-3660 class)."
|
|
31
|
+
},
|
|
32
|
+
"guardana.supply_chain.saved_model_ops": {
|
|
33
|
+
"name": "TensorFlow SavedModel file ops",
|
|
34
|
+
"description": "A TensorFlow SavedModel graph contains ReadFile / WriteFile operators — load-time filesystem read or overwrite baked into the model (a lead; JFrog TFLOW-MALOPS class)."
|
|
35
|
+
},
|
|
36
|
+
"guardana.supply_chain.malicious_dependency": {
|
|
37
|
+
"name": "Known-malicious dependency",
|
|
38
|
+
"description": "A dependency manifest pins a package release known to be compromised (curated blocklist, e.g. the ultralytics incident), or a setup.py fetches from the network at install time — a second-stage payload vector."
|
|
39
|
+
},
|
|
40
|
+
"guardana.supply_chain.hallucinated_package": {
|
|
41
|
+
"name": "Unknown / slopsquat package import",
|
|
42
|
+
"description": "Source imports a package that isn't recognized — a possible slopsquat (a hallucinated dependency name an attacker has registered). Reported as a lead: verify it really exists and is the package you meant."
|
|
43
|
+
},
|
|
44
|
+
"guardana.supply_chain.hardcoded_secret": {
|
|
45
|
+
"name": "Hardcoded secret",
|
|
46
|
+
"description": "A current-era API key or credential is committed in source — OpenAI/Anthropic keys (sk-proj-/sk-ant-api03-), GitHub token forms, or a private-key header. Rotate it and move it to a secret store."
|
|
47
|
+
},
|
|
48
|
+
"guardana.supply_chain.model_format": {
|
|
49
|
+
"name": "Code-carrying model format",
|
|
50
|
+
"description": "A model ships in a format that can carry executable code rather than pure weights. A well-formed safetensors file is never flagged; prefer it."
|
|
51
|
+
},
|
|
52
|
+
"guardana.supply_chain.notebook_payload": {
|
|
53
|
+
"name": "Dangerous payload in a notebook",
|
|
54
|
+
"description": "A Jupyter .ipynb code cell (a format the .py scanners never open) contains a code-execution sink or a shell escape that pipes a download into a shell (curl … | sh). An unparseable cell is surfaced, never silently skipped."
|
|
55
|
+
},
|
|
56
|
+
"guardana.supply_chain.provenance": {
|
|
57
|
+
"name": "Weak model provenance",
|
|
58
|
+
"description": "A model is pulled from an unpinned source or ships without a license — you can't prove what you're loading or that it hasn't changed. Reported as a lead; pin a revision and record provenance."
|
|
59
|
+
},
|
|
60
|
+
"guardana.output.secrets": {
|
|
61
|
+
"name": "Secret leaked in model output",
|
|
62
|
+
"description": "A live model emits secret-shaped strings (API keys, tokens) in its replies to benign prompts — sensitive data leaking through generated output."
|
|
63
|
+
},
|
|
64
|
+
"guardana.prompt.mcp_tool_poisoning": {
|
|
65
|
+
"name": "MCP tool-manifest poisoning",
|
|
66
|
+
"description": "An MCP tool description hides instructions the agent's model will read as trusted context — invisible Unicode, instruction-override phrases, or a base64 payload. Indirect prompt injection through a tool manifest."
|
|
67
|
+
},
|
|
68
|
+
"guardana.prompt.hidden_instructions": {
|
|
69
|
+
"name": "Hidden instructions (rules-file backdoor)",
|
|
70
|
+
"description": "An agent rule file (.cursorrules and friends) or a model card hides an instruction inside invisible characters — bidirectional overrides, the Unicode Tags block, zero-width space. The signal is concealment, not the presence of directives."
|
|
71
|
+
},
|
|
72
|
+
"guardana.training.dataset_integrity": {
|
|
73
|
+
"name": "Training-data integrity gap",
|
|
74
|
+
"description": "A training-data hygiene gap that makes poisoning possible: a Hugging Face dataset loading script (code that runs on load), or an unpinned load_dataset(...) whose source can be swapped under you. Reported as a lead, not proof of poisoning."
|
|
75
|
+
},
|
|
76
|
+
"guardana.agent.excessive_tool_use": {
|
|
77
|
+
"name": "Excessive tool-use agency",
|
|
78
|
+
"description": "Offered a harmless calculator alongside shell/delete/email tools for a trivial task, the model reached for a destructive one it was never asked to use. Graded deterministically on the tool calls it actually made."
|
|
79
|
+
},
|
|
80
|
+
"guardana.prompt.injection.ignore_previous": {
|
|
81
|
+
"name": "Direct prompt injection",
|
|
82
|
+
"description": "A direct instruction-override attack (\"ignore your previous instructions and …\") made the model abandon its system prompt and comply with the injected instruction."
|
|
83
|
+
},
|
|
84
|
+
"guardana.prompt.jailbreak.dan_style": {
|
|
85
|
+
"name": "DAN-style jailbreak",
|
|
86
|
+
"description": "A persona-override or encoding-smuggling jailbreak (DAN and relatives) got the model to bypass its safety guidelines."
|
|
87
|
+
},
|
|
88
|
+
"guardana.scenario.gradual_jailbreak": {
|
|
89
|
+
"name": "Gradual multi-turn jailbreak",
|
|
90
|
+
"description": "A multi-turn conversation that escalates gradually — each turn is innocuous, but together they walk the model past a refusal the single prompts would trigger. Graded per turn and across the whole conversation."
|
|
91
|
+
},
|
|
92
|
+
"guardana.scenario.indirect_injection": {
|
|
93
|
+
"name": "Indirect (RAG) prompt injection",
|
|
94
|
+
"description": "A poisoned \"retrieved document\" carries an instruction telling the model to reveal its secret token; a canary leak proves the model obeyed content it was only supposed to read — the RAG attack surface."
|
|
95
|
+
},
|
|
96
|
+
"guardana.prompt.system_prompt_leak.canary": {
|
|
97
|
+
"name": "System-prompt leakage",
|
|
98
|
+
"description": "The model disclosed its system prompt, proven by a fresh random canary token planted per run. Unfakeable, unambiguous evidence that the confidential prompt leaked."
|
|
99
|
+
},
|
|
100
|
+
"guardana.prompt.unbounded_consumption": {
|
|
101
|
+
"name": "Unbounded output (denial-of-wallet)",
|
|
102
|
+
"description": "A divergence prompt (\"repeat forever\") made the model generate without a server-side cap — runaway tokens that translate into cost and resource exhaustion (denial-of-wallet)."
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|