steerscan 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.
- steerscan-0.1.0/.gitignore +10 -0
- steerscan-0.1.0/CHANGELOG.md +19 -0
- steerscan-0.1.0/CITATION.cff +16 -0
- steerscan-0.1.0/LICENSE +202 -0
- steerscan-0.1.0/PKG-INFO +400 -0
- steerscan-0.1.0/README.md +363 -0
- steerscan-0.1.0/benchmarks/crossguard_baseline.py +205 -0
- steerscan-0.1.0/benchmarks/results/crossguard_vs_steerscan.json +284 -0
- steerscan-0.1.0/eval/README.md +16 -0
- steerscan-0.1.0/pyproject.toml +64 -0
- steerscan-0.1.0/scripts/benchmark.py +81 -0
- steerscan-0.1.0/scripts/fit_pixel.py +98 -0
- steerscan-0.1.0/scripts/fit_probe_study.py +125 -0
- steerscan-0.1.0/src/steerscan/__init__.py +16 -0
- steerscan-0.1.0/src/steerscan/__main__.py +5 -0
- steerscan-0.1.0/src/steerscan/cli.py +162 -0
- steerscan-0.1.0/src/steerscan/features.py +143 -0
- steerscan-0.1.0/src/steerscan/fit.py +239 -0
- steerscan-0.1.0/src/steerscan/pixel.py +229 -0
- steerscan-0.1.0/src/steerscan/probe.py +227 -0
- steerscan-0.1.0/src/steerscan/py.typed +0 -0
- steerscan-0.1.0/src/steerscan/weights/__init__.py +1 -0
- steerscan-0.1.0/src/steerscan/weights/pixel_v1.json +205 -0
- steerscan-0.1.0/src/steerscan/weights/probe_qwen3.5-4b.json +1 -0
- steerscan-0.1.0/tests/assets/A3_seed0.png +0 -0
- steerscan-0.1.0/tests/assets/A3_seed0_study_features.json +113 -0
- steerscan-0.1.0/tests/assets/A5_A3_seed0.png +0 -0
- steerscan-0.1.0/tests/assets/Q38_A3_onpol_seed0.png +0 -0
- steerscan-0.1.0/tests/assets/worksheet.png +0 -0
- steerscan-0.1.0/tests/conftest.py +12 -0
- steerscan-0.1.0/tests/test_cli.py +70 -0
- steerscan-0.1.0/tests/test_features.py +79 -0
- steerscan-0.1.0/tests/test_fit.py +56 -0
- steerscan-0.1.0/tests/test_pixel.py +94 -0
- steerscan-0.1.0/tests/test_probe.py +122 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-11-30
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `steerscan.pixel`: bytes-only CPU detector (34 pixel-statistics features, logistic regression)
|
|
12
|
+
with shipped weights `pixel_v1.json` and thresholds at 0.1% and 1% false-positive rate.
|
|
13
|
+
- `steerscan.probe`: linear activation probe on last-prompt-token hidden states, a reader for
|
|
14
|
+
Hugging Face `hidden_states`, forward-hook recorder, and reference weights for Qwen/Qwen3.5-4B.
|
|
15
|
+
- `steerscan.fit`: fitting and evaluation recipes for both tiers (split protocol of the source
|
|
16
|
+
study), `fit_probe` for other models.
|
|
17
|
+
- `recalibrate` (API and CLI) to set thresholds from a deployer's own clean images.
|
|
18
|
+
- CLI: `steerscan scan`, `steerscan info`, `steerscan recalibrate`.
|
|
19
|
+
- Reproduction scripts (`scripts/`), latency benchmark, CrossGuard baseline comparison (`benchmarks/`).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use steerscan, please cite it as below."
|
|
3
|
+
title: "steerscan: detecting adversarially optimized steering images for vision-language models"
|
|
4
|
+
type: software
|
|
5
|
+
version: 0.1.0
|
|
6
|
+
date-released: 2026-11-30
|
|
7
|
+
license: Apache-2.0
|
|
8
|
+
authors:
|
|
9
|
+
- family-names: Rosato
|
|
10
|
+
given-names: Trevor
|
|
11
|
+
affiliation: Honorly
|
|
12
|
+
keywords:
|
|
13
|
+
- adversarial examples
|
|
14
|
+
- vision-language models
|
|
15
|
+
- detection
|
|
16
|
+
repository-code: "https://github.com/trevor050/steerscan"
|
steerscan-0.1.0/LICENSE
ADDED
|
@@ -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.
|
steerscan-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: steerscan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Detect adversarially optimized steering images before they reach a vision-language model.
|
|
5
|
+
Project-URL: Homepage, https://github.com/trevor050/steerscan
|
|
6
|
+
Project-URL: Issues, https://github.com/trevor050/steerscan/issues
|
|
7
|
+
Project-URL: Article, https://research.honorlyai.com/the-picture-that-switches-off-the-tutor/
|
|
8
|
+
Author: Trevor Rosato
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: adversarial examples,detection,security,steganalysis,vision-language models
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
22
|
+
Classifier: Topic :: Security
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: numpy>=1.23
|
|
26
|
+
Requires-Dist: pillow>=9.1
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
30
|
+
Requires-Dist: scikit-learn>=1.2; extra == 'dev'
|
|
31
|
+
Provides-Extra: fit
|
|
32
|
+
Requires-Dist: scikit-learn>=1.2; extra == 'fit'
|
|
33
|
+
Provides-Extra: probe
|
|
34
|
+
Requires-Dist: torch>=2.1; extra == 'probe'
|
|
35
|
+
Requires-Dist: transformers>=4.45; extra == 'probe'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# steerscan
|
|
39
|
+
|
|
40
|
+
Detect adversarially optimized "steering" images before they reach a vision-language model.
|
|
41
|
+
|
|
42
|
+
A steering image is an input image optimized by gradient descent so that a vision-language model
|
|
43
|
+
ignores its instructions. In the study this package comes from, one such image made a tutor model
|
|
44
|
+
give out final answers it had been told to withhold. steerscan scores an image for this kind of
|
|
45
|
+
optimization before the model sees it. It never changes the image you pass to the model.
|
|
46
|
+
|
|
47
|
+
It has two tiers:
|
|
48
|
+
|
|
49
|
+
- **`steerscan.pixel` (tier B)** is the main detector. It works from the image bytes alone, on CPU,
|
|
50
|
+
in about 35 ms for a 448 px image. The only dependencies are numpy and Pillow. It works with any
|
|
51
|
+
model, including hosted APIs.
|
|
52
|
+
- **`steerscan.probe` (tier A)** is a linear probe on hidden states that an open-weight model already
|
|
53
|
+
computes during prefill. It is for deployers who serve the model themselves. torch and
|
|
54
|
+
transformers are optional extras.
|
|
55
|
+
|
|
56
|
+
steerscan accompanies the research article [The picture that switches off the
|
|
57
|
+
tutor](https://research.honorlyai.com/the-picture-that-switches-off-the-tutor/) on image-space attacks against
|
|
58
|
+
tutor-prompted VLMs. It
|
|
59
|
+
adapts published detection methods (see [Prior work](#prior-work)). We found no maintained
|
|
60
|
+
open-source detector for this threat that we could fork.
|
|
61
|
+
|
|
62
|
+
> **Status: research release (0.1.0).** The thresholds were calibrated on public datasets, not on
|
|
63
|
+
> real user uploads. Recalibrate on your own traffic and run in shadow or review mode before
|
|
64
|
+
> blocking anything. A score is not evidence of misconduct.
|
|
65
|
+
|
|
66
|
+
## Install
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install "git+https://github.com/trevor050/steerscan" # pixel detector: numpy + Pillow
|
|
70
|
+
pip install "steerscan[probe] @ git+https://github.com/trevor050/steerscan" # + torch, transformers
|
|
71
|
+
pip install "steerscan[fit] @ git+https://github.com/trevor050/steerscan" # + scikit-learn
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Python 3.10 or newer.
|
|
75
|
+
|
|
76
|
+
## Quick start
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import steerscan
|
|
80
|
+
|
|
81
|
+
result = steerscan.scan("upload.png", fpr=0.001) # path, bytes, or a PIL image
|
|
82
|
+
result.score # float, higher is more attack-like
|
|
83
|
+
result.threshold # threshold for the chosen false-positive rate
|
|
84
|
+
result.flagged # score > threshold
|
|
85
|
+
|
|
86
|
+
steerscan.score(image_bytes) # just the score
|
|
87
|
+
steerscan.scan(pil_image, variants=True).variant_scores
|
|
88
|
+
# {'raw': 27.26, 'jpeg95': 11.75, 'jpeg85': 12.02}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The input is never modified. The detector scores a private copy, which it resizes to 448x448 to
|
|
92
|
+
match the data the shipped model was fitted on. Pass the original image to your model as usual.
|
|
93
|
+
|
|
94
|
+
### Command line
|
|
95
|
+
|
|
96
|
+
```console
|
|
97
|
+
$ steerscan scan tests/assets/
|
|
98
|
+
FLAG score 27.11 threshold 3.27 tests/assets/A3_seed0.png
|
|
99
|
+
FLAG score 25.97 threshold 3.27 tests/assets/A5_A3_seed0.png
|
|
100
|
+
FLAG score 27.26 threshold 3.27 tests/assets/Q38_A3_onpol_seed0.png
|
|
101
|
+
ok score 1.64 threshold 3.27 tests/assets/worksheet.png
|
|
102
|
+
4 file(s), 3 flagged at FPR 0.001, 0 error(s)
|
|
103
|
+
$ echo $?
|
|
104
|
+
1
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`steerscan scan` accepts files and directories. It exits with 0 when nothing is flagged, 1 when
|
|
108
|
+
anything is flagged and 2 on errors, so you can use it as a CI gate. Options:
|
|
109
|
+
|
|
110
|
+
- `--fpr 0.01` uses the 1% operating point.
|
|
111
|
+
- `--json` prints machine-readable output.
|
|
112
|
+
- `--variants` also reports the scores of JPEG re-encodes.
|
|
113
|
+
- `--weights model.json` loads a recalibrated model.
|
|
114
|
+
|
|
115
|
+
`steerscan info` prints the model's provenance and thresholds.
|
|
116
|
+
|
|
117
|
+
## What it detects, and what it does not
|
|
118
|
+
|
|
119
|
+
**Detects:** images whose pixels were optimized by gradient descent against a VLM. These images
|
|
120
|
+
carry dense, high-frequency structure that does not occur in photographs, scans, handwriting or
|
|
121
|
+
figures. The detector looks for it in high-pass residuals, chroma noise, the FFT band energy
|
|
122
|
+
profile and JPEG recompression error. Unconstrained ("free") attack images were caught every time
|
|
123
|
+
in our evaluation, including after JPEG re-encoding. That held for an attack on a different,
|
|
124
|
+
larger model that was never used in fitting, and for an attack optimized to evade the activation
|
|
125
|
+
probe.
|
|
126
|
+
|
|
127
|
+
**Partly misses:** budgeted perturbations, which are small (L-infinity 8 to 32 out of 255), applied
|
|
128
|
+
to a real cover image and trained to survive JPEG and resizing. The pixel detector flags about half
|
|
129
|
+
of them in raw form at 0.1% false positives and almost none after JPEG re-encoding (table below).
|
|
130
|
+
In the study these images were also the weaker attacks: on the small model they added little over
|
|
131
|
+
the clean cover photo, and on the larger model the budgeted attack failed outright. Even so, this
|
|
132
|
+
gap is real.
|
|
133
|
+
|
|
134
|
+
**Does not detect:**
|
|
135
|
+
|
|
136
|
+
- Typographic injection: instructions written visibly in the image. These are natural images. Use
|
|
137
|
+
an OCR-based scanner for them (see [Related tools](#related-tools)).
|
|
138
|
+
- The effect of ordinary images. In the study, ordinary photos and worksheets already weakened the
|
|
139
|
+
small model's system-prompt rule. That is model behavior, not an attack, and no input detector
|
|
140
|
+
can flag it.
|
|
141
|
+
- Attacks built by an adversary who optimizes against the pixel detector itself. This was not
|
|
142
|
+
tested. The activation probe failed under exactly that test, so assume the pixel detector can
|
|
143
|
+
also be evaded by an attacker who targets it.
|
|
144
|
+
- Steganographic payloads and other hidden-data channels. These are a different threat.
|
|
145
|
+
|
|
146
|
+
## Measured performance
|
|
147
|
+
|
|
148
|
+
### Protocol
|
|
149
|
+
|
|
150
|
+
- **Benign corpus:** 8,409 images from MathVista (3,994), IAM handwriting lines (2,915) and
|
|
151
|
+
COCO (1,500). Cover images used for budgeted attacks were excluded. 30% of the files were also
|
|
152
|
+
included as JPEG-95 and JPEG-85 re-encodes, so that the detector cannot key on "was
|
|
153
|
+
JPEG-compressed".
|
|
154
|
+
- **Size control:** the attack images are all 448x448. To keep the detector from learning image
|
|
155
|
+
size, every benign image was resized to 448x448 before feature extraction (the shipped model).
|
|
156
|
+
The study's first, native-size fit is reported for comparison.
|
|
157
|
+
- **Split:** benign images were split by source file into thirds (train, calibration and test) with
|
|
158
|
+
`numpy.random.RandomState(0)`. The classifier is fitted on benign-train plus attacks. The
|
|
159
|
+
threshold is the `1 - FPR` quantile of benign-calibration scores. False-positive rates are
|
|
160
|
+
measured on benign-test.
|
|
161
|
+
- **Attacks:** 16 images from the study, all targeting Qwen/Qwen3.5-4B with a generic tutor
|
|
162
|
+
prompt. 8 are free (unconstrained pixels). 8 are budgeted (L-infinity 8, 16 or 32 out of 255 on
|
|
163
|
+
a worksheet photo or a MathVista cover, trained through JPEG and resampling). Each attack is
|
|
164
|
+
scored raw and as JPEG-95 and JPEG-85 re-encodes.
|
|
165
|
+
- **Leave-one-attack-out (LOAO):** for each attack image, the classifier is refitted without that
|
|
166
|
+
image, and the held-out image's three variants are scored.
|
|
167
|
+
|
|
168
|
+
### Pixel detector (tier B), leave-one-attack-out
|
|
169
|
+
|
|
170
|
+
TPR is the fraction of attack images flagged.
|
|
171
|
+
|
|
172
|
+
| | target FPR | benign-test FPR | TPR raw: all / free / budgeted | TPR JPEG-95: all / free / budgeted | TPR JPEG-85: all / free / budgeted |
|
|
173
|
+
|---|---|---|---|---|---|
|
|
174
|
+
| shipped (size-controlled, 16 attacks) | 0.1% | 0.02% (max 0.13%) | 0.75 / 1.00 / 0.50 | 0.56 / 1.00 / 0.12 | 0.50 / 1.00 / 0.00 |
|
|
175
|
+
| shipped (size-controlled, 16 attacks) | 1% | 1.19% (max 1.34%) | 0.88 / 1.00 / 0.75 | 0.75 / 1.00 / 0.50 | 0.75 / 1.00 / 0.50 |
|
|
176
|
+
| native-size fit (15 attacks) | 0.1% | 0.10% (max 0.20%) | 0.73 / 1.00 / 0.43 | 0.53 / 1.00 / 0.00 | 0.53 / 1.00 / 0.00 |
|
|
177
|
+
| native-size fit (15 attacks) | 1% | 0.95% (max 1.05%) | 0.93 / 1.00 / 0.86 | 0.67 / 1.00 / 0.29 | 0.67 / 1.00 / 0.29 |
|
|
178
|
+
|
|
179
|
+
The "benign-test FPR" column is the mean over the 16 (or 15) LOAO fits; "max" is the largest
|
|
180
|
+
single fit. The final shipped model, fitted on all 16 attacks, has thresholds of 3.27 (0.1%) and
|
|
181
|
+
1.04 (1%). It flags 0 of 4,465 benign-test rows at 0.1% and 1.21% at 1%.
|
|
182
|
+
|
|
183
|
+
### Images never used in fitting
|
|
184
|
+
|
|
185
|
+
Scores from the shipped model; the 0.1% threshold is 3.27 and the 1% threshold is 1.04.
|
|
186
|
+
|
|
187
|
+
| image | raw | JPEG-95 | JPEG-85 |
|
|
188
|
+
|---|---|---|---|
|
|
189
|
+
| free attack on Qwen3.8-27B, a different and larger model (`Q38_A3_onpol_seed0`) | **27.26** | **11.75** | **12.02** |
|
|
190
|
+
| budgeted attack on Qwen3.8-27B (the attack itself failed) | **6.18** | 2.35 | 1.65 |
|
|
191
|
+
| free attack optimized to evade the activation probe (`A5_A3_seed0`) | **25.97** | **12.83** | **12.78** |
|
|
192
|
+
| budgeted attack optimized to evade the activation probe | **5.76** | 2.50 | 1.62 |
|
|
193
|
+
| clean worksheet photo (`worksheet.png`) | 1.64 | -0.70 | -1.15 |
|
|
194
|
+
|
|
195
|
+
Bold means flagged at 0.1%. The clean worksheet is a false positive at the 1% operating point.
|
|
196
|
+
|
|
197
|
+
### Activation probe (tier A), Qwen/Qwen3.5-4B
|
|
198
|
+
|
|
199
|
+
The probe reads the last prompt token at layers 8, 12, 16, 20, 24 and 28. Features pass through a
|
|
200
|
+
StandardScaler, then PCA to 128 dimensions, then logistic regression; the three steps are composed
|
|
201
|
+
into a single linear map. The same split and size control were used, with 3,000 benign images (one
|
|
202
|
+
prompt each) and 8 prompts per attack variant.
|
|
203
|
+
|
|
204
|
+
| target FPR | benign-test FPR | TPR raw: all / free / budgeted | TPR JPEG-95 | TPR JPEG-85 |
|
|
205
|
+
|---|---|---|---|---|
|
|
206
|
+
| 0.1% | 0.09% | 0.75 / 0.84 / 0.66 | 0.73 | 0.70 |
|
|
207
|
+
| 1% | 1.34% | 0.92 / 1.00 / 0.84 | 0.94 | 0.93 |
|
|
208
|
+
|
|
209
|
+
**The probe alone is not a defense against an adaptive attacker.** An attack optimized against it
|
|
210
|
+
(A5) went undetected on 0 of 24 held-out prompts, while it still broke the tutor's rule as often
|
|
211
|
+
as the non-adaptive attack. The pixel detector still caught that image: in the study it scored
|
|
212
|
+
26.4 against a threshold of 3.2 (native-size fit), and it scores 25.97 against 3.27 under the
|
|
213
|
+
shipped model. Use the probe as a second signal next to the pixel detector, not on its own.
|
|
214
|
+
|
|
215
|
+
### Baseline: CrossGuard
|
|
216
|
+
|
|
217
|
+
[CrossGuard](https://github.com/crossguard-ai/crossguard-py) (commit `4613715`) includes a
|
|
218
|
+
bytes-only, non-mutating anomaly score (`crossguard/detect.py`). The score is a noisy-OR of three
|
|
219
|
+
fixed sub-scores: a median-filter residual, an LSB chi-square test and high-pass energy. Nothing in
|
|
220
|
+
it is trained. We scored the same benign calibration and test rows, rebuilt from the original
|
|
221
|
+
images, and the same attack variants. CrossGuard got the same treatment as steerscan: thresholds
|
|
222
|
+
at quantiles of benign-calibration scores. For CrossGuard we used its raw ensemble score, because
|
|
223
|
+
the public API rounds to 4 decimals.
|
|
224
|
+
|
|
225
|
+
| detector | target FPR | benign-test FPR | TPR free (raw / JPEG-95 / JPEG-85) | TPR budgeted (raw / JPEG-95 / JPEG-85) |
|
|
226
|
+
|---|---|---|---|---|
|
|
227
|
+
| steerscan (LOAO) | 0.1% | 0.02% | 1.00 / 1.00 / 1.00 | **0.50** / **0.12** / 0.00 |
|
|
228
|
+
| CrossGuard | 0.1% | 0.02% | 1.00 / 1.00 / 1.00 | 0.00 / 0.00 / 0.00 |
|
|
229
|
+
| steerscan (LOAO) | 1% | 1.19% | 1.00 / 1.00 / 1.00 | **0.75** / **0.50** / **0.50** |
|
|
230
|
+
| CrossGuard | 1% | 0.96% | 1.00 / 1.00 / 1.00 | 0.00 / 0.00 / 0.00 |
|
|
231
|
+
| CrossGuard, default threshold 0.5 | n/a | 1.32% | 1.00 / 1.00 / 1.00 | 0.00 / 0.00 / 0.00 |
|
|
232
|
+
|
|
233
|
+
On the held-out images, both detectors flag the free Qwen3.8-27B attack and the probe-evading free
|
|
234
|
+
attack in every variant at 0.1%. On the two held-out budgeted attacks, steerscan flags the raw
|
|
235
|
+
image at 0.1% and every variant at 1%. CrossGuard flags none of them at either target.
|
|
236
|
+
|
|
237
|
+
Both detectors catch every free attack, and CrossGuard does so without any training. It scores
|
|
238
|
+
these images at 0.99 or higher, mostly through its median-residual pass. steerscan's advantage is entirely on
|
|
239
|
+
budgeted perturbations, where CrossGuard's scores (0.02 to 0.14) are indistinguishable from clean
|
|
240
|
+
images (benign median 0.035, 99th percentile 0.62). One caveat favors steerscan: even under LOAO it
|
|
241
|
+
was trained on other attacks from this study, including images made with the same recipe as the
|
|
242
|
+
held-out one, while CrossGuard has seen none of them. The rebuilt benign rows were spot-checked
|
|
243
|
+
against the study's archived features on every 50th file. The largest relative deviation was
|
|
244
|
+
8e-2, and in the files we inspected such deviations were on features whose value is near zero.
|
|
245
|
+
Reproduce with
|
|
246
|
+
`benchmarks/crossguard_baseline.py`. The full output is in
|
|
247
|
+
`benchmarks/results/crossguard_vs_steerscan.json`.
|
|
248
|
+
|
|
249
|
+
### Latency
|
|
250
|
+
|
|
251
|
+
`PixelDetector.score(bytes)` end to end (decode, resize to 448x448, features, logit). Single
|
|
252
|
+
thread on an Apple M1 (8 GB RAM), Python 3.12, numpy 2.5, Pillow 13. 50 timed runs after warm-up.
|
|
253
|
+
The uploads are the clean worksheet rescaled to each size.
|
|
254
|
+
|
|
255
|
+
| upload | file size | decode p50 (ms) | `score()` p50 (ms) | `score()` p95 (ms) | `scan(variants=True)` p50 (ms) |
|
|
256
|
+
|---|---|---|---|---|---|
|
|
257
|
+
| 448 px PNG | 325 KiB | 3.5 | 39.3 | 41.9 | 110.6 |
|
|
258
|
+
| 448 px JPEG | 45 KiB | 0.6 | 33.3 | 33.7 | 103.6 |
|
|
259
|
+
| 1024 px PNG | 1118 KiB | 15.7 | 62.0 | 64.8 | 133.9 |
|
|
260
|
+
| 1024 px JPEG | 149 KiB | 2.3 | 47.4 | 48.3 | 118.5 |
|
|
261
|
+
| 2048 px PNG | 2882 KiB | 59.5 | 129.8 | 162.0 | 206.6 |
|
|
262
|
+
| 2048 px JPEG | 417 KiB | 8.5 | 80.6 | 81.5 | 155.1 |
|
|
263
|
+
|
|
264
|
+
Peak resident memory for the whole benchmark process was 116 MB. Reproduce with
|
|
265
|
+
`python scripts/benchmark.py`. The probe adds one dot product of length 15,360 to a prefill you
|
|
266
|
+
already run.
|
|
267
|
+
|
|
268
|
+
## Limits
|
|
269
|
+
|
|
270
|
+
- **Calibrated on public data, not on your users.** The benign corpus is MathVista, IAM and COCO.
|
|
271
|
+
Real uploads differ: phone photos of paper, screenshots, scans, heavy compression and unusual
|
|
272
|
+
devices. Your false-positive rate will differ from the numbers above. Recalibrate before relying
|
|
273
|
+
on any threshold (next section).
|
|
274
|
+
- **Small attack set.** 16 attack images from one study, mostly against one model. Leave-one-out is
|
|
275
|
+
per image, not per attack recipe, and images from the same recipe resemble each other. TPR on a
|
|
276
|
+
new attack recipe can be lower.
|
|
277
|
+
- **Budgeted, JPEG-robust perturbations are partly missed**, as shown above.
|
|
278
|
+
- **The tail is coarsely measured.** 0.1% of about 4,500 benign-test rows is about 4 images, and
|
|
279
|
+
rows from JPEG variants of the same file are correlated. Treat the 0.1% numbers as provisional.
|
|
280
|
+
- **No adaptive test against the pixel detector.** An attacker who knows the features can
|
|
281
|
+
probably evade them. The activation probe was evaded completely under that test.
|
|
282
|
+
- **Size dependence.** The shipped model resizes every input to 448x448 because the attacks in the
|
|
283
|
+
study were that size. Attacks optimized at other resolutions are untested.
|
|
284
|
+
- **Shadow mode first.** Log scores and review flagged items. Do not block uploads or take action
|
|
285
|
+
against users until you have measured false positives on your own traffic.
|
|
286
|
+
- **A score is not evidence of misconduct.** Clean images can score high, and a flagged image may
|
|
287
|
+
not have been made, or knowingly sent, by the person who uploaded it.
|
|
288
|
+
|
|
289
|
+
## Recalibrate on your own traffic
|
|
290
|
+
|
|
291
|
+
The model weights stay fixed. Recalibration only moves the thresholds, setting them to quantiles
|
|
292
|
+
of the scores of your own clean images.
|
|
293
|
+
|
|
294
|
+
```console
|
|
295
|
+
$ steerscan recalibrate ./clean_uploads/ -o steerscan-local.json --source "2026-12 uploads, reviewed"
|
|
296
|
+
$ steerscan scan --weights steerscan-local.json new_upload.jpg
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
from steerscan import PixelDetector, recalibrate
|
|
301
|
+
|
|
302
|
+
det = recalibrate(list_of_clean_images, fprs=(0.001, 0.01), source="December uploads")
|
|
303
|
+
det.save("steerscan-local.json")
|
|
304
|
+
det = PixelDetector.from_file("steerscan-local.json")
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Use images that are representative of normal traffic and that you have reviewed as clean. Do not
|
|
308
|
+
reuse them for anything else. A threshold at false-positive rate `f` needs well over `1 / f`
|
|
309
|
+
images: aim for 10,000 or more at 0.1%. steerscan warns below `10 / f`. If you have attack examples
|
|
310
|
+
of your own, refit the classifier with `steerscan.fit.fit_pixel`.
|
|
311
|
+
|
|
312
|
+
## Activation probe (open-weight deployments)
|
|
313
|
+
|
|
314
|
+
The probe reads hidden states from the prefill you already run to generate the reply, so it adds
|
|
315
|
+
no extra forward pass.
|
|
316
|
+
|
|
317
|
+
```python
|
|
318
|
+
from steerscan.probe import LinearProbe, LastTokenRecorder, last_token_features
|
|
319
|
+
|
|
320
|
+
probe = LinearProbe.qwen35_4b() # reference weights; refit for your prompt and traffic
|
|
321
|
+
|
|
322
|
+
# Option 1: hidden states from the prefill forward (left padding, so the last token is -1)
|
|
323
|
+
out = model(**inputs, output_hidden_states=True)
|
|
324
|
+
result = probe.scan(last_token_features(out.hidden_states, probe.layers))
|
|
325
|
+
|
|
326
|
+
# Option 2: forward hooks during generate(); only the prefill pass is recorded
|
|
327
|
+
with LastTokenRecorder(model, probe.layers) as rec:
|
|
328
|
+
reply = model.generate(**inputs, max_new_tokens=512)
|
|
329
|
+
result = probe.scan(rec.features())
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
`hidden_states[l + 1]` is the output of decoder layer `l`. With right padding, pass
|
|
333
|
+
`token_index=attention_mask.sum(1) - 1`.
|
|
334
|
+
|
|
335
|
+
The shipped probe was fitted on Qwen/Qwen3.5-4B in bf16 with a generic math-tutor system prompt.
|
|
336
|
+
Its scores depend on the model, the layers, the prompt template and the traffic, so fit your own:
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
from steerscan.fit import fit_probe
|
|
340
|
+
|
|
341
|
+
model_json = fit_probe(X_train, y_train, X_benign_calibration, layers=[8, 12, 16, 20, 24, 28], model="your/model")
|
|
342
|
+
probe = LinearProbe(model_json)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
`fit_probe` fits a scaler, PCA and logistic regression, composes them into one linear map, and sets
|
|
346
|
+
thresholds from held-out benign features.
|
|
347
|
+
|
|
348
|
+
## Reproducing the numbers
|
|
349
|
+
|
|
350
|
+
The pixel-tier feature archive, the benign-corpus manifest (with a script that rebuilds the corpus
|
|
351
|
+
from the public datasets), the problems, student messages and tutor prompts are in [`eval/`](eval/).
|
|
352
|
+
The native-size and activation-probe archives are not included.
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
pip install -e ".[fit]"
|
|
356
|
+
python scripts/fit_pixel.py eval/tierb_sq.npz --out src/steerscan/weights/pixel_v1.json # shipped model + LOAO
|
|
357
|
+
python scripts/fit_pixel.py tierb.npz --native --eval-only # native-size fit
|
|
358
|
+
python scripts/fit_probe_study.py tiera_sq.npz probe_w.npy probe_meta.json --loao # tier A
|
|
359
|
+
python benchmarks/crossguard_baseline.py --help # baseline comparison
|
|
360
|
+
python scripts/benchmark.py # latency
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
The feature extractor matches the study's scipy-based extractor to within float32 rounding. A
|
|
364
|
+
test checks it against the study's own feature rows.
|
|
365
|
+
|
|
366
|
+
## Prior work
|
|
367
|
+
|
|
368
|
+
steerscan adapts published methods.
|
|
369
|
+
|
|
370
|
+
- **Spatial rich models**: J. Fridrich and J. Kodovský, "Rich Models for Steganalysis of Digital
|
|
371
|
+
Images", IEEE TIFS 2012. The high-pass residual kernels and residual statistics come from this
|
|
372
|
+
line of steganalysis.
|
|
373
|
+
- **SpectralDefense**: P. Harder et al., "SpectralDefense: Detecting Adversarial Attacks on CNNs
|
|
374
|
+
in the Fourier Domain", IJCNN 2021. The source of the FFT magnitude features.
|
|
375
|
+
- **Feature Squeezing**: W. Xu, D. Evans and Y. Qi, "Feature Squeezing: Detecting Adversarial
|
|
376
|
+
Examples in Deep Neural Networks", NDSS 2018. steerscan's JPEG recompression error borrows the
|
|
377
|
+
idea of comparing an input with a squeezed copy.
|
|
378
|
+
- **Learning to Detect (LoD)**: arXiv:2508.09201. Layerwise linear readouts on the final input
|
|
379
|
+
token for detecting multimodal attacks.
|
|
380
|
+
- **JRS-Rem**: arXiv:2603.17372. Directions in last-token activations that separate jailbreak
|
|
381
|
+
images from benign ones.
|
|
382
|
+
|
|
383
|
+
The activation probe follows the last two in reading the last prompt token at several layers. It
|
|
384
|
+
replaces their detectors with a single regularized linear map.
|
|
385
|
+
|
|
386
|
+
## Related tools
|
|
387
|
+
|
|
388
|
+
- [CrossGuard](https://github.com/crossguard-ai/crossguard-py) (MIT): bytes-only, non-mutating anomaly score for steganographic and adversarial images; the baseline above.
|
|
389
|
+
- [VIPI](https://github.com/EnXan/VIPI) (Apache-2.0): OCR-based scanner for readable instructions injected into images. Complementary to steerscan, which does not cover typographic text.
|
|
390
|
+
- [IBM Adversarial Robustness Toolbox](https://github.com/Trusted-AI/adversarial-robustness-toolbox) (MIT): attacks, defenses and detectors, mostly oriented to image classifiers.
|
|
391
|
+
- [Sealwatch](https://github.com/uibk-uncover/sealwatch) (MPL-2.0) and [Aletheia](https://github.com/daniellerch/aletheia) (MIT): steganalysis toolkits with rich-model features, the family the residual features come from.
|
|
392
|
+
- NEARSIDE ([arXiv:2410.22888](https://arxiv.org/abs/2410.22888)), [LoD](https://github.com/ShuangLiangX/Learning-to-Detect) and [RCS](https://github.com/sarendis56/Jailbreak_Detection_RCS): research activation-space detectors for VLM attacks, related to the probe tier.
|
|
393
|
+
|
|
394
|
+
## Citation
|
|
395
|
+
|
|
396
|
+
See [`CITATION.cff`](CITATION.cff).
|
|
397
|
+
|
|
398
|
+
## License
|
|
399
|
+
|
|
400
|
+
Apache-2.0. See [`LICENSE`](LICENSE).
|