local-image-gen-security 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.
- local_image_gen_security-0.1.0/LICENSE +202 -0
- local_image_gen_security-0.1.0/NOTICE +5 -0
- local_image_gen_security-0.1.0/PKG-INFO +76 -0
- local_image_gen_security-0.1.0/README.md +56 -0
- local_image_gen_security-0.1.0/pyproject.toml +36 -0
- local_image_gen_security-0.1.0/setup.cfg +4 -0
- local_image_gen_security-0.1.0/src/ligsp/__init__.py +9 -0
- local_image_gen_security-0.1.0/src/ligsp/__main__.py +106 -0
- local_image_gen_security-0.1.0/src/ligsp/ext.py +79 -0
- local_image_gen_security-0.1.0/src/ligsp/files.py +70 -0
- local_image_gen_security-0.1.0/src/ligsp/fixes.py +44 -0
- local_image_gen_security-0.1.0/src/ligsp/models.py +104 -0
- local_image_gen_security-0.1.0/src/ligsp/net.py +132 -0
- local_image_gen_security-0.1.0/src/ligsp/report.py +72 -0
- local_image_gen_security-0.1.0/src/ligsp/results.py +33 -0
- local_image_gen_security-0.1.0/src/ligsp/targets.py +59 -0
- local_image_gen_security-0.1.0/src/ligsp/transport.py +107 -0
- local_image_gen_security-0.1.0/src/ligsp/web.py +69 -0
- local_image_gen_security-0.1.0/src/ligsp/winacl.py +146 -0
- local_image_gen_security-0.1.0/src/local_image_gen_security.egg-info/PKG-INFO +76 -0
- local_image_gen_security-0.1.0/src/local_image_gen_security.egg-info/SOURCES.txt +23 -0
- local_image_gen_security-0.1.0/src/local_image_gen_security.egg-info/dependency_links.txt +1 -0
- local_image_gen_security-0.1.0/src/local_image_gen_security.egg-info/entry_points.txt +3 -0
- local_image_gen_security-0.1.0/src/local_image_gen_security.egg-info/top_level.txt +1 -0
- local_image_gen_security-0.1.0/tests/test_checker.py +383 -0
|
@@ -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,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: local-image-gen-security
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Checks a local image-generation setup (ComfyUI, A1111 / Forge, hubs, model folders) against the Local Image Generation Security Profile: read-only, only where you point it
|
|
5
|
+
Author: 33rd-kk
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/33rd-kk/local-image-gen-security
|
|
8
|
+
Project-URL: Issues, https://github.com/33rd-kk/local-image-gen-security/issues
|
|
9
|
+
Keywords: security,comfyui,stable-diffusion,image-generation,safetensors,checker
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
License-File: NOTICE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# ligsp: the LIGSP checker
|
|
22
|
+
|
|
23
|
+
Checks the image-generation servers and model folders you name against the
|
|
24
|
+
Local Image Generation Security Profile ([profile.md](https://github.com/33rd-kk/local-image-gen-security/blob/main/profile.md)). It is
|
|
25
|
+
read-only, and it contacts only the places you point it at.
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
ligsp check http://127.0.0.1:8188 # a ComfyUI
|
|
29
|
+
ligsp check http://127.0.0.1:7860 --models D:\models # A1111 / Forge and a model folder
|
|
30
|
+
ligsp check http://127.0.0.1:3000 --redact # a report you can share
|
|
31
|
+
ligsp check --private C:\latentry # who can read Latentry's settings and keys
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Common default ports: ComfyUI 8188, Comfy Desktop 8000, A1111 / Forge 7860,
|
|
35
|
+
Latentry 3000, InvokeAI 9090, SwarmUI 7801. It tries no port you did not
|
|
36
|
+
name.
|
|
37
|
+
|
|
38
|
+
## What it checks
|
|
39
|
+
|
|
40
|
+
| ID | What |
|
|
41
|
+
|---|---|
|
|
42
|
+
| NET-1 | Whether a server on 127.0.0.1 also answers on this computer's network addresses (IPv4 and IPv6) |
|
|
43
|
+
| NET-2 | Whether it can be used from the network without a login or pairing |
|
|
44
|
+
| BE-1 | A server on another computer reached over plain HTTP |
|
|
45
|
+
| WEB-1 | Whether other websites may read its answers (CORS) |
|
|
46
|
+
| WEB-2 | Whether it answers for any host name (DNS rebinding) |
|
|
47
|
+
| WEB-3 | Protective headers on its page |
|
|
48
|
+
| EXT-1 | An extension installer on the server (ComfyUI-Manager), and how many node packs or A1111 extensions it runs (counts only, never names) |
|
|
49
|
+
| DATA-4 | Who besides you can read a hub's private files (`--private FILE` or a folder; Latentry's settings and keys are found by name). Only permissions are read, never content. |
|
|
50
|
+
| MOD-1 | Weight files in a pickle format (`.ckpt`, `.pt`, `.pth`, `.bin`, `.pkl`), files named `.safetensors` that are really pickles, and safetensors headers that do not read |
|
|
51
|
+
|
|
52
|
+
Exit code 0 when nothing failed, 1 when something failed, 2 for a usage
|
|
53
|
+
error. `--json FILE` (or `-`) writes the same report as JSON.
|
|
54
|
+
|
|
55
|
+
## What it does not do
|
|
56
|
+
|
|
57
|
+
- It sends only GET, HEAD and OPTIONS, only to a fixed list of endpoints
|
|
58
|
+
known to change nothing, with no query strings, to the URLs you give and
|
|
59
|
+
to the same port on this computer's own addresses. One function sends
|
|
60
|
+
every request, and it refuses anything else (`transport.py`). A safe
|
|
61
|
+
method alone is not enough: some servers act on a GET (ComfyUI-Manager
|
|
62
|
+
removes or restores snapshots on one). It never queues a job, uploads a
|
|
63
|
+
file or changes a setting.
|
|
64
|
+
- It reads only the fields it needs. ComfyUI's `/system_stats` also lists
|
|
65
|
+
the server's command line; that is dropped unread.
|
|
66
|
+
- In model folders it opens only `.safetensors` files, and only to read
|
|
67
|
+
their header. It follows no links out of the folder.
|
|
68
|
+
- For private files it reads only their permissions: the mode, or on
|
|
69
|
+
Windows the access list, through the Windows API and compared by account
|
|
70
|
+
ID (SID), so it works in any system language.
|
|
71
|
+
- It sends no telemetry and checks for no updates, and it writes no file
|
|
72
|
+
unless you ask (`--json FILE`).
|
|
73
|
+
- A pass means these checks found no problem, not that the setup is safe.
|
|
74
|
+
|
|
75
|
+
Standard library only (Python 3.10+). Tests: `pytest` in this folder, with
|
|
76
|
+
`src` on the path.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# ligsp: the LIGSP checker
|
|
2
|
+
|
|
3
|
+
Checks the image-generation servers and model folders you name against the
|
|
4
|
+
Local Image Generation Security Profile ([profile.md](https://github.com/33rd-kk/local-image-gen-security/blob/main/profile.md)). It is
|
|
5
|
+
read-only, and it contacts only the places you point it at.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
ligsp check http://127.0.0.1:8188 # a ComfyUI
|
|
9
|
+
ligsp check http://127.0.0.1:7860 --models D:\models # A1111 / Forge and a model folder
|
|
10
|
+
ligsp check http://127.0.0.1:3000 --redact # a report you can share
|
|
11
|
+
ligsp check --private C:\latentry # who can read Latentry's settings and keys
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Common default ports: ComfyUI 8188, Comfy Desktop 8000, A1111 / Forge 7860,
|
|
15
|
+
Latentry 3000, InvokeAI 9090, SwarmUI 7801. It tries no port you did not
|
|
16
|
+
name.
|
|
17
|
+
|
|
18
|
+
## What it checks
|
|
19
|
+
|
|
20
|
+
| ID | What |
|
|
21
|
+
|---|---|
|
|
22
|
+
| NET-1 | Whether a server on 127.0.0.1 also answers on this computer's network addresses (IPv4 and IPv6) |
|
|
23
|
+
| NET-2 | Whether it can be used from the network without a login or pairing |
|
|
24
|
+
| BE-1 | A server on another computer reached over plain HTTP |
|
|
25
|
+
| WEB-1 | Whether other websites may read its answers (CORS) |
|
|
26
|
+
| WEB-2 | Whether it answers for any host name (DNS rebinding) |
|
|
27
|
+
| WEB-3 | Protective headers on its page |
|
|
28
|
+
| EXT-1 | An extension installer on the server (ComfyUI-Manager), and how many node packs or A1111 extensions it runs (counts only, never names) |
|
|
29
|
+
| DATA-4 | Who besides you can read a hub's private files (`--private FILE` or a folder; Latentry's settings and keys are found by name). Only permissions are read, never content. |
|
|
30
|
+
| MOD-1 | Weight files in a pickle format (`.ckpt`, `.pt`, `.pth`, `.bin`, `.pkl`), files named `.safetensors` that are really pickles, and safetensors headers that do not read |
|
|
31
|
+
|
|
32
|
+
Exit code 0 when nothing failed, 1 when something failed, 2 for a usage
|
|
33
|
+
error. `--json FILE` (or `-`) writes the same report as JSON.
|
|
34
|
+
|
|
35
|
+
## What it does not do
|
|
36
|
+
|
|
37
|
+
- It sends only GET, HEAD and OPTIONS, only to a fixed list of endpoints
|
|
38
|
+
known to change nothing, with no query strings, to the URLs you give and
|
|
39
|
+
to the same port on this computer's own addresses. One function sends
|
|
40
|
+
every request, and it refuses anything else (`transport.py`). A safe
|
|
41
|
+
method alone is not enough: some servers act on a GET (ComfyUI-Manager
|
|
42
|
+
removes or restores snapshots on one). It never queues a job, uploads a
|
|
43
|
+
file or changes a setting.
|
|
44
|
+
- It reads only the fields it needs. ComfyUI's `/system_stats` also lists
|
|
45
|
+
the server's command line; that is dropped unread.
|
|
46
|
+
- In model folders it opens only `.safetensors` files, and only to read
|
|
47
|
+
their header. It follows no links out of the folder.
|
|
48
|
+
- For private files it reads only their permissions: the mode, or on
|
|
49
|
+
Windows the access list, through the Windows API and compared by account
|
|
50
|
+
ID (SID), so it works in any system language.
|
|
51
|
+
- It sends no telemetry and checks for no updates, and it writes no file
|
|
52
|
+
unless you ask (`--json FILE`).
|
|
53
|
+
- A pass means these checks found no problem, not that the setup is safe.
|
|
54
|
+
|
|
55
|
+
Standard library only (Python 3.10+). Tests: `pytest` in this folder, with
|
|
56
|
+
`src` on the path.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "local-image-gen-security"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Checks a local image-generation setup (ComfyUI, A1111 / Forge, hubs, model folders) against the Local Image Generation Security Profile: read-only, only where you point it"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "33rd-kk" }]
|
|
14
|
+
keywords = ["security", "comfyui", "stable-diffusion", "image-generation", "safetensors", "checker"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: End Users/Desktop",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Security",
|
|
21
|
+
]
|
|
22
|
+
dependencies = []
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/33rd-kk/local-image-gen-security"
|
|
26
|
+
Issues = "https://github.com/33rd-kk/local-image-gen-security/issues"
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
ligsp = "ligsp.__main__:main"
|
|
30
|
+
local-image-gen-security = "ligsp.__main__:main"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|
|
34
|
+
|
|
35
|
+
[tool.ruff]
|
|
36
|
+
line-length = 140
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Checks a local image-generation setup against the Local Image Generation Security Profile.
|
|
2
|
+
|
|
3
|
+
Read-only: it sends GET, HEAD and OPTIONS only, to the servers you name and
|
|
4
|
+
to this computer's own addresses, and opens model files only to read
|
|
5
|
+
safetensors headers. See checker/DESIGN.md.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
PROFILE_VERSION = "0.1"
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""ligsp check URL ... [--models DIR ...] [--json FILE] [--redact]"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from urllib.parse import urlsplit
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .ext import extension_checks
|
|
12
|
+
from .files import file_checks
|
|
13
|
+
from .models import model_checks
|
|
14
|
+
from .net import network_checks, own_lan_addresses
|
|
15
|
+
from .report import Redactor, as_json, as_text, summary
|
|
16
|
+
from .results import FAIL, Target
|
|
17
|
+
from .targets import identify
|
|
18
|
+
from .transport import Transport
|
|
19
|
+
from .web import web_checks
|
|
20
|
+
|
|
21
|
+
DEFAULT_PORTS = "ComfyUI 8188, Comfy Desktop 8000, A1111 / Forge 7860, Latentry 3000, InvokeAI 9090, SwarmUI 7801"
|
|
22
|
+
|
|
23
|
+
DESCRIPTION = f"""\
|
|
24
|
+
Checks the image-generation servers and model folders you name against the
|
|
25
|
+
Local Image Generation Security Profile. Read-only: it sends GET, HEAD and OPTIONS
|
|
26
|
+
only, to the URLs you give and to the same port on this computer's own
|
|
27
|
+
network addresses, and it reads only the headers of .safetensors files.
|
|
28
|
+
It tries no other ports. Common defaults: {DEFAULT_PORTS}.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def check_server(transport: Transport, url: str, lan: list[str]) -> Target:
|
|
33
|
+
transport.allow_url(url)
|
|
34
|
+
found = identify(transport, url)
|
|
35
|
+
target = Target(url, found.kind, found.version)
|
|
36
|
+
results, reachable = network_checks(transport, url, found, lan)
|
|
37
|
+
target.results.extend(results)
|
|
38
|
+
if found.answer is not None:
|
|
39
|
+
web = web_checks(transport, url, found, reachable)
|
|
40
|
+
target.results.extend(web)
|
|
41
|
+
any_host = any(r.id == "WEB-2" and r.status in ("warn", "fail") for r in web)
|
|
42
|
+
target.results.extend(extension_checks(transport, url, found, reachable, any_host))
|
|
43
|
+
return target
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main(argv: list[str] | None = None) -> int:
|
|
47
|
+
parser = argparse.ArgumentParser(prog="ligsp", description=DESCRIPTION, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
48
|
+
parser.add_argument("--version", action="version", version=f"ligsp {__version__}")
|
|
49
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
50
|
+
check = sub.add_parser("check", help="check servers and model folders", description=DESCRIPTION, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
51
|
+
check.add_argument("urls", nargs="*", metavar="URL", help="a server to check, e.g. http://127.0.0.1:8188")
|
|
52
|
+
check.add_argument("--models", action="append", default=[], metavar="DIR", help="a model folder to check (may be repeated)")
|
|
53
|
+
check.add_argument("--private", action="append", default=[], metavar="PATH",
|
|
54
|
+
help="a private file, or a folder with a hub's private files (Latentry's settings and keys), whose permissions to check")
|
|
55
|
+
check.add_argument("--json", metavar="FILE", help="also write the report as JSON to FILE ('-' for standard output only)")
|
|
56
|
+
check.add_argument("--redact", action="store_true", help="hide paths, host names, addresses and ports, to share the report")
|
|
57
|
+
args = parser.parse_args(argv)
|
|
58
|
+
|
|
59
|
+
for url in args.urls:
|
|
60
|
+
if urlsplit(url).scheme not in ("http", "https") or not urlsplit(url).hostname:
|
|
61
|
+
parser.error(f"not an http(s) URL: {url}")
|
|
62
|
+
if not args.urls and not args.models and not args.private:
|
|
63
|
+
parser.error(f"name at least one server URL, --models folder or --private path (common ports: {DEFAULT_PORTS})")
|
|
64
|
+
|
|
65
|
+
redact = Redactor(args.redact)
|
|
66
|
+
transport = Transport()
|
|
67
|
+
lan = own_lan_addresses() if args.urls else []
|
|
68
|
+
for address in lan:
|
|
69
|
+
redact.add(address, "<this computer>")
|
|
70
|
+
targets: list[Target] = []
|
|
71
|
+
for index, url in enumerate(args.urls, 1):
|
|
72
|
+
parts = urlsplit(url)
|
|
73
|
+
if parts.hostname and parts.hostname not in ("127.0.0.1", "localhost", "::1"):
|
|
74
|
+
redact.add(parts.hostname, f"<host{index}>")
|
|
75
|
+
if parts.port:
|
|
76
|
+
redact.add(f":{parts.port}", ":<port>")
|
|
77
|
+
targets.append(check_server(transport, url, lan))
|
|
78
|
+
for index, folder in enumerate(args.models, 1):
|
|
79
|
+
path = Path(folder)
|
|
80
|
+
redact.add(str(path.resolve()), f"<models{index}>")
|
|
81
|
+
redact.add(folder, f"<models{index}>")
|
|
82
|
+
target = Target(folder, "models")
|
|
83
|
+
target.results.extend(model_checks(path))
|
|
84
|
+
targets.append(target)
|
|
85
|
+
for index, place in enumerate(args.private, 1):
|
|
86
|
+
path = Path(place)
|
|
87
|
+
redact.add(str(path.resolve()), f"<private{index}>")
|
|
88
|
+
redact.add(place, f"<private{index}>")
|
|
89
|
+
target = Target(place, "files")
|
|
90
|
+
target.results.extend(file_checks(path))
|
|
91
|
+
targets.append(target)
|
|
92
|
+
redact.add(str(Path.home()), "<home>")
|
|
93
|
+
|
|
94
|
+
if args.json != "-":
|
|
95
|
+
print(as_text(targets, redact))
|
|
96
|
+
if args.json:
|
|
97
|
+
data = as_json(targets, redact)
|
|
98
|
+
if args.json == "-":
|
|
99
|
+
print(data)
|
|
100
|
+
else:
|
|
101
|
+
Path(args.json).write_text(data + "\n", encoding="utf-8")
|
|
102
|
+
return 1 if summary(targets)[FAIL] else 0
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
sys.exit(main())
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Extensions (EXT-1): what runs other people's code on the server, from read-only endpoints.
|
|
2
|
+
|
|
3
|
+
ComfyUI lists the browser scripts of its custom nodes at /extensions, one
|
|
4
|
+
folder per node pack that has a web part (so the count is a lower bound);
|
|
5
|
+
ComfyUI-Manager answers its version at /v2/manager/version (or the older
|
|
6
|
+
/manager/version). A1111 / Forge list their extensions at
|
|
7
|
+
/sdapi/v1/extensions. Only counts and the Manager's version are kept, never
|
|
8
|
+
the names.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
|
|
15
|
+
from . import fixes
|
|
16
|
+
from .results import FAIL, PASS, WARN, Result
|
|
17
|
+
from .targets import Identified
|
|
18
|
+
from .transport import Transport
|
|
19
|
+
|
|
20
|
+
MANAGER_PATHS = ("/v2/manager/version", "/manager/version")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _json(answer) -> object:
|
|
24
|
+
if answer is None or answer.status != 200:
|
|
25
|
+
return None
|
|
26
|
+
try:
|
|
27
|
+
return json.loads(answer.body.decode("utf-8"))
|
|
28
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def extension_checks(transport: Transport, base: str, found: Identified, reachable_from_network: bool, any_host: bool) -> list[Result]:
|
|
33
|
+
"""`any_host`: it answers for any host name (WEB-2), so a web page could reach it too."""
|
|
34
|
+
base = base.rstrip("/")
|
|
35
|
+
if found.kind == "comfyui":
|
|
36
|
+
return _comfyui(transport, base, reachable_from_network, any_host)
|
|
37
|
+
if found.kind == "a1111":
|
|
38
|
+
return _a1111(transport, base)
|
|
39
|
+
return []
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _comfyui(transport: Transport, base: str, reachable_from_network: bool, any_host: bool) -> list[Result]:
|
|
43
|
+
results: list[Result] = []
|
|
44
|
+
listed = _json(transport.request("GET", base + "/extensions"))
|
|
45
|
+
packs = None
|
|
46
|
+
if isinstance(listed, list):
|
|
47
|
+
packs = len({item.split("/")[2] for item in listed if isinstance(item, str) and item.startswith("/extensions/") and item.count("/") >= 3} - {"core"})
|
|
48
|
+
|
|
49
|
+
manager = None
|
|
50
|
+
for path in MANAGER_PATHS:
|
|
51
|
+
answer = transport.request("GET", base + path)
|
|
52
|
+
if answer is not None and answer.status == 200 and len(answer.body) < 64:
|
|
53
|
+
manager = answer.body.decode("utf-8", "replace").strip().strip('"') or "found"
|
|
54
|
+
break
|
|
55
|
+
|
|
56
|
+
evidence = []
|
|
57
|
+
if packs is not None:
|
|
58
|
+
evidence.append(f"at least {packs} custom node pack(s) with a web part")
|
|
59
|
+
if manager:
|
|
60
|
+
evidence.append(f"ComfyUI-Manager {manager}")
|
|
61
|
+
if reachable_from_network:
|
|
62
|
+
status, title = FAIL, "An extension installer (ComfyUI-Manager) can be used from the network"
|
|
63
|
+
elif any_host:
|
|
64
|
+
status, title = WARN, "An extension installer (ComfyUI-Manager) is on a server that answers any host name"
|
|
65
|
+
else:
|
|
66
|
+
status, title = WARN, "An extension installer (ComfyUI-Manager) is part of this server"
|
|
67
|
+
results.append(Result("EXT-1", status, title, evidence, fixes.WHY["EXT-1"], fixes.fix("EXT-1", "comfyui")))
|
|
68
|
+
else:
|
|
69
|
+
results.append(Result("EXT-1", PASS, "No extension installer answered", evidence))
|
|
70
|
+
return results
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _a1111(transport: Transport, base: str) -> list[Result]:
|
|
74
|
+
listed = _json(transport.request("GET", base + "/sdapi/v1/extensions"))
|
|
75
|
+
if not isinstance(listed, list):
|
|
76
|
+
return []
|
|
77
|
+
enabled = sum(1 for item in listed if isinstance(item, dict) and item.get("enabled"))
|
|
78
|
+
return [Result("EXT-1", PASS if enabled == 0 else WARN, f"{enabled} extension(s) enabled", [f"{len(listed)} installed, {enabled} enabled"],
|
|
79
|
+
fixes.WHY["EXT-1"], fixes.fix("EXT-1", "a1111"))]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Private files (DATA-4, AUTH-5): settings, keys and tokens that only their owner may read.
|
|
2
|
+
|
|
3
|
+
A file is named with --private. A folder named there is searched (not
|
|
4
|
+
recursively) for the private files of the hubs the checker knows (Latentry's
|
|
5
|
+
settings file, pairing key, paired-device list and folder-name key). Only
|
|
6
|
+
the files' permissions are read, never their content.
|
|
7
|
+
|
|
8
|
+
On POSIX that is the mode. On Windows it is the access list, compared by
|
|
9
|
+
SID (see winacl.py), so it works in any system language. Entries for the
|
|
10
|
+
owner, SYSTEM and Administrators are fine; any other account or group
|
|
11
|
+
(Users, Everyone, Authenticated Users, another person) fails.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import stat
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from . import fixes, winacl
|
|
21
|
+
from .results import FAIL, PASS, UNKNOWN, Result
|
|
22
|
+
|
|
23
|
+
KNOWN_PRIVATE = ("latentry.settings.json", "latentry.pairing-key", "latentry.pairing-devices.json", "latentry.folder-names-key")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def private_files(path: Path) -> list[Path]:
|
|
27
|
+
if path.is_dir():
|
|
28
|
+
return [path / name for name in KNOWN_PRIVATE if (path / name).is_file()]
|
|
29
|
+
return [path] if path.is_file() else []
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def others_who_can_read(file: Path, platform: str = sys.platform) -> list[str] | None:
|
|
33
|
+
"""Who besides the owner (and Windows itself) can read `file`; None when unknown."""
|
|
34
|
+
if platform == "win32":
|
|
35
|
+
found = winacl.readers(str(file))
|
|
36
|
+
me = winacl.current_user_sid()
|
|
37
|
+
if found is None or me is None:
|
|
38
|
+
return None
|
|
39
|
+
fine = {me, winacl.SYSTEM, winacl.ADMINISTRATORS}
|
|
40
|
+
return sorted({name for sid, name in found if sid not in fine})
|
|
41
|
+
mode = file.stat().st_mode
|
|
42
|
+
others = []
|
|
43
|
+
if mode & stat.S_IRGRP:
|
|
44
|
+
others.append("its group")
|
|
45
|
+
if mode & stat.S_IROTH:
|
|
46
|
+
others.append("every user")
|
|
47
|
+
return others
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def file_checks(path: Path) -> list[Result]:
|
|
51
|
+
files = private_files(path)
|
|
52
|
+
if not files:
|
|
53
|
+
return [Result("DATA-4", UNKNOWN, "No private file found there" + (" (looked for: " + ", ".join(KNOWN_PRIVATE) + ")" if path.is_dir() else ""))]
|
|
54
|
+
open_files: list[str] = []
|
|
55
|
+
unknown: list[str] = []
|
|
56
|
+
for file in files:
|
|
57
|
+
others = others_who_can_read(file)
|
|
58
|
+
if others is None:
|
|
59
|
+
unknown.append(file.name)
|
|
60
|
+
elif others:
|
|
61
|
+
open_files.append(f"{file.name}: also readable by {', '.join(others)}")
|
|
62
|
+
results = []
|
|
63
|
+
if open_files:
|
|
64
|
+
results.append(Result("DATA-4", FAIL, f"{len(open_files)} private file(s) can be read by others", open_files, fixes.WHY["DATA-4"], fixes.fix("DATA-4", "files")))
|
|
65
|
+
readable = len(files) - len(open_files) - len(unknown)
|
|
66
|
+
if readable:
|
|
67
|
+
results.append(Result("DATA-4", PASS, f"{readable} private file(s) readable by their owner only", [f.name for f in files if f.name not in unknown and not any(o.startswith(f.name + ":") for o in open_files)]))
|
|
68
|
+
if unknown:
|
|
69
|
+
results.append(Result("DATA-4", UNKNOWN, "Could not read the permissions of some files", unknown))
|
|
70
|
+
return results
|