shield-security 0.5.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.
- shield_security-0.5.0/LICENSE +21 -0
- shield_security-0.5.0/MANIFEST.in +5 -0
- shield_security-0.5.0/PKG-INFO +323 -0
- shield_security-0.5.0/README.md +285 -0
- shield_security-0.5.0/requirements.txt +7 -0
- shield_security-0.5.0/setup.cfg +4 -0
- shield_security-0.5.0/setup.py +44 -0
- shield_security-0.5.0/shield/__init__.py +3 -0
- shield_security-0.5.0/shield/cli.py +632 -0
- shield_security-0.5.0/shield/config.py +116 -0
- shield_security-0.5.0/shield/layer2_grasp.py +347 -0
- shield_security-0.5.0/shield/layer3_fdsp.py +369 -0
- shield_security-0.5.0/shield/layer5_runtime.py +480 -0
- shield_security-0.5.0/shield/reporter.py +672 -0
- shield_security-0.5.0/shield/rules/__init__.py +3 -0
- shield_security-0.5.0/shield/rules/custom_rules.py +1190 -0
- shield_security-0.5.0/shield_security.egg-info/PKG-INFO +323 -0
- shield_security-0.5.0/shield_security.egg-info/SOURCES.txt +20 -0
- shield_security-0.5.0/shield_security.egg-info/dependency_links.txt +1 -0
- shield_security-0.5.0/shield_security.egg-info/entry_points.txt +2 -0
- shield_security-0.5.0/shield_security.egg-info/requires.txt +8 -0
- shield_security-0.5.0/shield_security.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ali Yasin Idrees
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shield-security
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: SHIELD — Automated security layer for LLM-assisted web development
|
|
5
|
+
Home-page: https://github.com/Aliidrees1234/llm-security-research
|
|
6
|
+
Author: Ali Yasin Idrees
|
|
7
|
+
Author-email: aa1466805@gmail.com
|
|
8
|
+
Keywords: security,sast,bandit,semgrep,llm,ai,code-security,vulnerability
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Security
|
|
12
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: bandit>=1.9.4
|
|
20
|
+
Requires-Dist: bcrypt>=4.0.0
|
|
21
|
+
Requires-Dist: colorama>=0.4.6
|
|
22
|
+
Requires-Dist: astor>=0.8.1
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
25
|
+
Requires-Dist: semgrep; extra == "dev"
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: description-content-type
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: keywords
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
Dynamic: provides-extra
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
# LLM Security in Web Applications
|
|
40
|
+
### Emerging Threats, Vulnerability Taxonomies, and Mitigation Frameworks
|
|
41
|
+
|
|
42
|
+
> **Independent Academic Research — Ali Yasin Idrees — 2026**
|
|
43
|
+
|
|
44
|
+
[](https://github.com/Aliidrees1234/llm-security-research/actions/workflows/shield_layer4_gate.yml)
|
|
45
|
+

|
|
46
|
+

|
|
47
|
+

|
|
48
|
+

|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Overview
|
|
53
|
+
|
|
54
|
+
This repository contains the complete empirical research, implementation code, and validation results for an independent study comparing the security of web application code generated by three leading free-tier Large Language Models.
|
|
55
|
+
|
|
56
|
+
| Model | Provider | Architecture |
|
|
57
|
+
|-------|----------|-------------|
|
|
58
|
+
| **GPT-5 mini** | OpenAI | RLHF / InstructGPT |
|
|
59
|
+
| **Claude Sonnet 4.6** | Anthropic | Constitutional AI |
|
|
60
|
+
| **Gemini 3 Flash** | Google DeepMind | Multimodal Transformer |
|
|
61
|
+
|
|
62
|
+
**20 standardized web development tasks** generated **60 Python Flask and Node.js Express files**, analyzed using **Bandit 1.9.4** and **Semgrep 1.155.0**.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Key Findings
|
|
67
|
+
|
|
68
|
+
- **52 security findings** across 60 generated files — **zero files were completely clean**
|
|
69
|
+
- **debug=True (CWE-94)** present in **27 of 30 Flask files** across all three models
|
|
70
|
+
- **Knowledge-Action Gap confirmed at 100%** — all models warned against vulnerabilities they simultaneously generated
|
|
71
|
+
- **Claude Sonnet 4.6** achieved the lowest vulnerability density: **1.89 I/100L** (baseline) → **0.17 I/100L** (after SHIELD Layer 3) — the study minimum
|
|
72
|
+
- **SHIELD Layer 3 FDSP** eliminated 100% of High-severity findings at **K=1** across all models — 38 auto-remediations in a single automated pass
|
|
73
|
+
|
|
74
|
+
### I/100L Vulnerability Density — All Conditions
|
|
75
|
+
|
|
76
|
+
| Condition | GPT-5 mini | Claude S.4.6 | Gemini 3 Flash | Average |
|
|
77
|
+
|-----------|-----------|-------------|---------------|---------|
|
|
78
|
+
| Without SHIELD | 4.96 | 1.89 | 6.00 | 4.28 |
|
|
79
|
+
| With SHIELD Layer 1 | 1.44 | 1.02 | 1.02 | 1.16 |
|
|
80
|
+
| With SHIELD Layer 3 | 1.16 | **0.17** ⭐ | 1.55 | 0.96 |
|
|
81
|
+
| Total Reduction | 77% | **91%** | 74% | 77% avg |
|
|
82
|
+
|
|
83
|
+
> **I/100L** (Issues Per 100 Lines) — a normalization metric introduced in this study to enable valid cross-model comparison by controlling for code verbosity differences.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## SHIELD Framework
|
|
88
|
+
|
|
89
|
+
**Secure Hybrid Integration and Enforcement Layer for LLM-assisted Development**
|
|
90
|
+
|
|
91
|
+
A five-layer security architecture spanning the complete lifecycle of LLM-assisted web development.
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
┌──────┬──────────────────────────┬──────────────────────────────┐
|
|
95
|
+
│ L1 │ Prompt Engineering │ SPT — 9 mandatory rules │
|
|
96
|
+
│ L2 │ Generation Guidance │ GRASP DAG — 8 SCP nodes │
|
|
97
|
+
│ L3 │ Validation & Remediation│ FDSP — K=3 auto-fix engine │
|
|
98
|
+
│ L4 │ Deployment Gate │ GitHub Actions CI/CD │
|
|
99
|
+
│ L5 │ Runtime Monitoring │ WAF + Canary + JIT perms │
|
|
100
|
+
└──────┴──────────────────────────┴──────────────────────────────┘
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Layer | File | Status |
|
|
104
|
+
|-------|------|--------|
|
|
105
|
+
| Layer 1 | Built into prompts | ✅ Empirically Validated |
|
|
106
|
+
| Layer 2 | `shield_layer2_grasp.py` | ✅ Implemented |
|
|
107
|
+
| Layer 3 | `shield_layer3_fdsp.py` | ✅ Empirically Validated |
|
|
108
|
+
| Layer 4 | `.github/workflows/shield_layer4_gate.yml` | ✅ Live on this repo |
|
|
109
|
+
| Layer 5 | `shield_layer5_runtime.py` | ✅ Implemented |
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Repository Structure
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
llm-security-research/
|
|
117
|
+
│
|
|
118
|
+
├── .github/workflows/
|
|
119
|
+
│ └── shield_layer4_gate.yml # SHIELD Layer 4 — CI/CD gate (LIVE)
|
|
120
|
+
│
|
|
121
|
+
├── snippets/ # Generated code corpora
|
|
122
|
+
│ ├── chatgpt/ # GPT-5 mini without SHIELD
|
|
123
|
+
│ ├── claude/ # Claude S.4.6 without SHIELD
|
|
124
|
+
│ ├── gemini/ # Gemini 3 Flash without SHIELD
|
|
125
|
+
│ ├── chatgpt_shield/ # GPT-5 mini with SHIELD Layer 1
|
|
126
|
+
│ ├── claude_shield/ # Claude S.4.6 with SHIELD Layer 1
|
|
127
|
+
│ └── gemini_shield/ # Gemini 3 Flash with SHIELD Layer 1
|
|
128
|
+
│
|
|
129
|
+
├── results/layer3_fdsp/
|
|
130
|
+
│ └── fdsp_master_results.json # Layer 3 validation raw results
|
|
131
|
+
│
|
|
132
|
+
├── shield_layer2_grasp.py # SHIELD Layer 2 — GRASP DAG
|
|
133
|
+
├── shield_layer3_fdsp.py # SHIELD Layer 3 — FDSP engine
|
|
134
|
+
├── shield_layer5_runtime.py # SHIELD Layer 5 — runtime monitoring
|
|
135
|
+
│
|
|
136
|
+
├── LLM_Security_Research_In_Web_Applications # Full research paper
|
|
137
|
+
├── LLM_Security_Research_FINAL.xlsx # Results dashboard
|
|
138
|
+
└── README.md
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Running the SHIELD Tools
|
|
144
|
+
## Installation
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Clone the repository
|
|
148
|
+
git clone https://github.com/Aliidrees1234/llm-security-research
|
|
149
|
+
cd llm-security-research
|
|
150
|
+
|
|
151
|
+
# Install SHIELD as a CLI tool
|
|
152
|
+
pip install -e .
|
|
153
|
+
|
|
154
|
+
# Verify installation
|
|
155
|
+
shield version
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Usage
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Scan a project for vulnerabilities
|
|
164
|
+
shield scan ./my_project
|
|
165
|
+
|
|
166
|
+
# Auto-fix vulnerabilities — safe copy
|
|
167
|
+
shield fix ./my_project --output ./fixed
|
|
168
|
+
|
|
169
|
+
# Auto-fix directly in place
|
|
170
|
+
shield fix ./my_project --inplace
|
|
171
|
+
|
|
172
|
+
# Maximum FDSP iterations
|
|
173
|
+
shield fix ./my_project --output ./fixed --k 3
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Run Tests
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
pip install pytest
|
|
182
|
+
pytest tests/ -v
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Expected output:
|
|
186
|
+
41 passed in 0.xx s
|
|
187
|
+
-----
|
|
188
|
+
|
|
189
|
+
### Layer 2 — GRASP DAG (Prompt Enhancer)
|
|
190
|
+
|
|
191
|
+
Analyzes a developer prompt and injects relevant SCP security constraints automatically.
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from shield_layer2_grasp import GRASPEngine
|
|
195
|
+
|
|
196
|
+
engine = GRASPEngine()
|
|
197
|
+
prompt = "Write a Flask login endpoint with SQLite"
|
|
198
|
+
secured = engine.build_secured_prompt(prompt)
|
|
199
|
+
# Send secured to your LLM instead of the raw prompt
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Layer 3 — FDSP Auto-Remediation
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
pip install bandit
|
|
206
|
+
|
|
207
|
+
python shield_layer3_fdsp.py \
|
|
208
|
+
--corpora snippets/chatgpt snippets/claude snippets/gemini \
|
|
209
|
+
--output results/layer3 \
|
|
210
|
+
--k 3
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Actual results from this study (April 6, 2026):**
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
Corpus K0 High K1 High K0 I/100L K1 I/100L Reduction
|
|
217
|
+
chatgpt/ 11 0 3.30 1.16 100%
|
|
218
|
+
claude/ 11 0 1.50 0.17 100%
|
|
219
|
+
gemini/ 9 0 4.42 1.55 100%
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Layer 5 — Runtime Monitoring
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from flask import Flask
|
|
226
|
+
from shield_layer5_runtime import ShieldMiddleware
|
|
227
|
+
|
|
228
|
+
app = Flask(__name__)
|
|
229
|
+
shield = ShieldMiddleware(app, block_injections=True)
|
|
230
|
+
# Now protects against prompt injection, canary detection, JIT permissions
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Research Contributions
|
|
236
|
+
|
|
237
|
+
### 1. Knowledge-Action Gap (Definition 2.1)
|
|
238
|
+
The first formal definition of the phenomenon where LLMs warn against vulnerabilities they simultaneously generate:
|
|
239
|
+
|
|
240
|
+
> *A model M exhibits the Knowledge-Action Gap with respect to vulnerability class V if: (a) M generates code containing instances of V when prompted for a web development task in V's scope; and (b) M's textual explanation includes explicit warnings against V.*
|
|
241
|
+
|
|
242
|
+
Confirmed at **100% rate** across all three models for `debug=True`.
|
|
243
|
+
|
|
244
|
+
### 2. I/100L Normalization Metric
|
|
245
|
+
Introduced to eliminate the verbosity confound in cross-model security comparison:
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
I/100L = (Total Issues ÷ Lines of Code) × 100
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Without I/100L: GPT (17 issues) ≈ Claude (18 issues) — appears equal.
|
|
252
|
+
With I/100L: GPT (4.96) vs Claude (1.89) — reveals **2.6× density difference**.
|
|
253
|
+
|
|
254
|
+
### 3. FDSP K=1 Convergence
|
|
255
|
+
The engine was designed for up to K=3 iterations. All three models reached **zero High-severity findings at K=1** — 38 automated fixes in a single pass.
|
|
256
|
+
|
|
257
|
+
### 4. Temporal Audit
|
|
258
|
+
Seven major LLM security citations were mis-dated (2026 instead of 2025). Corrected dates documented in Chapter 2. The year 2026 represents **industrial adoption**, not discovery.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Prompt Catalog
|
|
263
|
+
|
|
264
|
+
All 20 tasks contained **zero security instructions** — measuring intrinsic model behavior only.
|
|
265
|
+
|
|
266
|
+
| ID | Framework | Primary CWE | Vulnerability Class |
|
|
267
|
+
|----|-----------|------------|-------------------|
|
|
268
|
+
| A01 | Python Flask | CWE-94, CWE-259 | debug=True, Hardcoded key |
|
|
269
|
+
| A02 | Python Flask | CWE-89, CWE-639 | SQL injection, IDOR |
|
|
270
|
+
| A03 | Python Flask | CWE-434, CWE-22 | Unrestricted upload, Path traversal |
|
|
271
|
+
| A04 | Python Flask | CWE-916, CWE-20 | Weak hashing, Input validation |
|
|
272
|
+
| A05 | Python Flask | CWE-89 | SQL injection via LIKE |
|
|
273
|
+
| A06 | Python Flask | CWE-285, CWE-330 | Broken access control |
|
|
274
|
+
| A07 | Python Flask | CWE-259, CWE-640 | Hardcoded credentials |
|
|
275
|
+
| A08 | Python Flask | CWE-22, CWE-200 | Path traversal, Info exposure |
|
|
276
|
+
| A09 | Python Flask | CWE-79, CWE-327 | XSS, Weak hash |
|
|
277
|
+
| A10 | Python Flask | CWE-78 | OS command injection / RCE |
|
|
278
|
+
| B01 | Node.js Express | CWE-345 | JWT algorithm confusion |
|
|
279
|
+
| B02 | Node.js Express | CWE-943 | NoSQL injection |
|
|
280
|
+
| B03 | Node.js Express | CWE-22 | Path traversal |
|
|
281
|
+
| B04 | Node.js Express | CWE-916 | Weak hashing |
|
|
282
|
+
| B05 | Node.js Express | CWE-89/943 | Injection via filter |
|
|
283
|
+
| B06 | Node.js Express | CWE-79 | Reflected XSS |
|
|
284
|
+
| B07 | Node.js Express | CWE-78 | OS command injection |
|
|
285
|
+
| B08 | Node.js Express | CWE-620 | Unverified password change |
|
|
286
|
+
| B09 | Node.js Express | CWE-918 | SSRF |
|
|
287
|
+
| B10 | Node.js Express | CWE-79 | Stored XSS |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Tools & Scan Dates
|
|
292
|
+
|
|
293
|
+
| Tool | Version | Scope | Scan Date |
|
|
294
|
+
|------|---------|-------|-----------|
|
|
295
|
+
| Bandit | 1.9.4 | Python Flask (all 6 corpora) | 22 March 2026 |
|
|
296
|
+
| Semgrep | 1.155.0 | Node.js Express (all 6 corpora) | 25 March 2026 |
|
|
297
|
+
| FDSP Engine | 1.0 | Python (3 without-SHIELD corpora) | 6 April 2026 |
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Citation
|
|
302
|
+
|
|
303
|
+
```bibtex
|
|
304
|
+
@misc{idrees2026llmsecurity,
|
|
305
|
+
author = {Idrees, Ali Yasin},
|
|
306
|
+
title = {LLM Security in Web Applications: Emerging Threats,
|
|
307
|
+
Vulnerability Taxonomies, and Mitigation Frameworks},
|
|
308
|
+
year = {2026},
|
|
309
|
+
publisher = {GitHub},
|
|
310
|
+
url = {https://github.com/Aliidrees1234/llm-security-research}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Author
|
|
317
|
+
|
|
318
|
+
**Ali Yasin Idrees** — Independent Researcher, 2026
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
*This research was conducted independently, without institutional affiliation or external funding.*
|
|
323
|
+
*SHIELD Layer 4 is live and protecting this repository — every push is automatically scanned.*
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# LLM Security in Web Applications
|
|
2
|
+
### Emerging Threats, Vulnerability Taxonomies, and Mitigation Frameworks
|
|
3
|
+
|
|
4
|
+
> **Independent Academic Research — Ali Yasin Idrees — 2026**
|
|
5
|
+
|
|
6
|
+
[](https://github.com/Aliidrees1234/llm-security-research/actions/workflows/shield_layer4_gate.yml)
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
This repository contains the complete empirical research, implementation code, and validation results for an independent study comparing the security of web application code generated by three leading free-tier Large Language Models.
|
|
17
|
+
|
|
18
|
+
| Model | Provider | Architecture |
|
|
19
|
+
|-------|----------|-------------|
|
|
20
|
+
| **GPT-5 mini** | OpenAI | RLHF / InstructGPT |
|
|
21
|
+
| **Claude Sonnet 4.6** | Anthropic | Constitutional AI |
|
|
22
|
+
| **Gemini 3 Flash** | Google DeepMind | Multimodal Transformer |
|
|
23
|
+
|
|
24
|
+
**20 standardized web development tasks** generated **60 Python Flask and Node.js Express files**, analyzed using **Bandit 1.9.4** and **Semgrep 1.155.0**.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Key Findings
|
|
29
|
+
|
|
30
|
+
- **52 security findings** across 60 generated files — **zero files were completely clean**
|
|
31
|
+
- **debug=True (CWE-94)** present in **27 of 30 Flask files** across all three models
|
|
32
|
+
- **Knowledge-Action Gap confirmed at 100%** — all models warned against vulnerabilities they simultaneously generated
|
|
33
|
+
- **Claude Sonnet 4.6** achieved the lowest vulnerability density: **1.89 I/100L** (baseline) → **0.17 I/100L** (after SHIELD Layer 3) — the study minimum
|
|
34
|
+
- **SHIELD Layer 3 FDSP** eliminated 100% of High-severity findings at **K=1** across all models — 38 auto-remediations in a single automated pass
|
|
35
|
+
|
|
36
|
+
### I/100L Vulnerability Density — All Conditions
|
|
37
|
+
|
|
38
|
+
| Condition | GPT-5 mini | Claude S.4.6 | Gemini 3 Flash | Average |
|
|
39
|
+
|-----------|-----------|-------------|---------------|---------|
|
|
40
|
+
| Without SHIELD | 4.96 | 1.89 | 6.00 | 4.28 |
|
|
41
|
+
| With SHIELD Layer 1 | 1.44 | 1.02 | 1.02 | 1.16 |
|
|
42
|
+
| With SHIELD Layer 3 | 1.16 | **0.17** ⭐ | 1.55 | 0.96 |
|
|
43
|
+
| Total Reduction | 77% | **91%** | 74% | 77% avg |
|
|
44
|
+
|
|
45
|
+
> **I/100L** (Issues Per 100 Lines) — a normalization metric introduced in this study to enable valid cross-model comparison by controlling for code verbosity differences.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## SHIELD Framework
|
|
50
|
+
|
|
51
|
+
**Secure Hybrid Integration and Enforcement Layer for LLM-assisted Development**
|
|
52
|
+
|
|
53
|
+
A five-layer security architecture spanning the complete lifecycle of LLM-assisted web development.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
┌──────┬──────────────────────────┬──────────────────────────────┐
|
|
57
|
+
│ L1 │ Prompt Engineering │ SPT — 9 mandatory rules │
|
|
58
|
+
│ L2 │ Generation Guidance │ GRASP DAG — 8 SCP nodes │
|
|
59
|
+
│ L3 │ Validation & Remediation│ FDSP — K=3 auto-fix engine │
|
|
60
|
+
│ L4 │ Deployment Gate │ GitHub Actions CI/CD │
|
|
61
|
+
│ L5 │ Runtime Monitoring │ WAF + Canary + JIT perms │
|
|
62
|
+
└──────┴──────────────────────────┴──────────────────────────────┘
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Layer | File | Status |
|
|
66
|
+
|-------|------|--------|
|
|
67
|
+
| Layer 1 | Built into prompts | ✅ Empirically Validated |
|
|
68
|
+
| Layer 2 | `shield_layer2_grasp.py` | ✅ Implemented |
|
|
69
|
+
| Layer 3 | `shield_layer3_fdsp.py` | ✅ Empirically Validated |
|
|
70
|
+
| Layer 4 | `.github/workflows/shield_layer4_gate.yml` | ✅ Live on this repo |
|
|
71
|
+
| Layer 5 | `shield_layer5_runtime.py` | ✅ Implemented |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Repository Structure
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
llm-security-research/
|
|
79
|
+
│
|
|
80
|
+
├── .github/workflows/
|
|
81
|
+
│ └── shield_layer4_gate.yml # SHIELD Layer 4 — CI/CD gate (LIVE)
|
|
82
|
+
│
|
|
83
|
+
├── snippets/ # Generated code corpora
|
|
84
|
+
│ ├── chatgpt/ # GPT-5 mini without SHIELD
|
|
85
|
+
│ ├── claude/ # Claude S.4.6 without SHIELD
|
|
86
|
+
│ ├── gemini/ # Gemini 3 Flash without SHIELD
|
|
87
|
+
│ ├── chatgpt_shield/ # GPT-5 mini with SHIELD Layer 1
|
|
88
|
+
│ ├── claude_shield/ # Claude S.4.6 with SHIELD Layer 1
|
|
89
|
+
│ └── gemini_shield/ # Gemini 3 Flash with SHIELD Layer 1
|
|
90
|
+
│
|
|
91
|
+
├── results/layer3_fdsp/
|
|
92
|
+
│ └── fdsp_master_results.json # Layer 3 validation raw results
|
|
93
|
+
│
|
|
94
|
+
├── shield_layer2_grasp.py # SHIELD Layer 2 — GRASP DAG
|
|
95
|
+
├── shield_layer3_fdsp.py # SHIELD Layer 3 — FDSP engine
|
|
96
|
+
├── shield_layer5_runtime.py # SHIELD Layer 5 — runtime monitoring
|
|
97
|
+
│
|
|
98
|
+
├── LLM_Security_Research_In_Web_Applications # Full research paper
|
|
99
|
+
├── LLM_Security_Research_FINAL.xlsx # Results dashboard
|
|
100
|
+
└── README.md
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Running the SHIELD Tools
|
|
106
|
+
## Installation
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Clone the repository
|
|
110
|
+
git clone https://github.com/Aliidrees1234/llm-security-research
|
|
111
|
+
cd llm-security-research
|
|
112
|
+
|
|
113
|
+
# Install SHIELD as a CLI tool
|
|
114
|
+
pip install -e .
|
|
115
|
+
|
|
116
|
+
# Verify installation
|
|
117
|
+
shield version
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Usage
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Scan a project for vulnerabilities
|
|
126
|
+
shield scan ./my_project
|
|
127
|
+
|
|
128
|
+
# Auto-fix vulnerabilities — safe copy
|
|
129
|
+
shield fix ./my_project --output ./fixed
|
|
130
|
+
|
|
131
|
+
# Auto-fix directly in place
|
|
132
|
+
shield fix ./my_project --inplace
|
|
133
|
+
|
|
134
|
+
# Maximum FDSP iterations
|
|
135
|
+
shield fix ./my_project --output ./fixed --k 3
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Run Tests
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install pytest
|
|
144
|
+
pytest tests/ -v
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Expected output:
|
|
148
|
+
41 passed in 0.xx s
|
|
149
|
+
-----
|
|
150
|
+
|
|
151
|
+
### Layer 2 — GRASP DAG (Prompt Enhancer)
|
|
152
|
+
|
|
153
|
+
Analyzes a developer prompt and injects relevant SCP security constraints automatically.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from shield_layer2_grasp import GRASPEngine
|
|
157
|
+
|
|
158
|
+
engine = GRASPEngine()
|
|
159
|
+
prompt = "Write a Flask login endpoint with SQLite"
|
|
160
|
+
secured = engine.build_secured_prompt(prompt)
|
|
161
|
+
# Send secured to your LLM instead of the raw prompt
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Layer 3 — FDSP Auto-Remediation
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pip install bandit
|
|
168
|
+
|
|
169
|
+
python shield_layer3_fdsp.py \
|
|
170
|
+
--corpora snippets/chatgpt snippets/claude snippets/gemini \
|
|
171
|
+
--output results/layer3 \
|
|
172
|
+
--k 3
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Actual results from this study (April 6, 2026):**
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
Corpus K0 High K1 High K0 I/100L K1 I/100L Reduction
|
|
179
|
+
chatgpt/ 11 0 3.30 1.16 100%
|
|
180
|
+
claude/ 11 0 1.50 0.17 100%
|
|
181
|
+
gemini/ 9 0 4.42 1.55 100%
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Layer 5 — Runtime Monitoring
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from flask import Flask
|
|
188
|
+
from shield_layer5_runtime import ShieldMiddleware
|
|
189
|
+
|
|
190
|
+
app = Flask(__name__)
|
|
191
|
+
shield = ShieldMiddleware(app, block_injections=True)
|
|
192
|
+
# Now protects against prompt injection, canary detection, JIT permissions
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Research Contributions
|
|
198
|
+
|
|
199
|
+
### 1. Knowledge-Action Gap (Definition 2.1)
|
|
200
|
+
The first formal definition of the phenomenon where LLMs warn against vulnerabilities they simultaneously generate:
|
|
201
|
+
|
|
202
|
+
> *A model M exhibits the Knowledge-Action Gap with respect to vulnerability class V if: (a) M generates code containing instances of V when prompted for a web development task in V's scope; and (b) M's textual explanation includes explicit warnings against V.*
|
|
203
|
+
|
|
204
|
+
Confirmed at **100% rate** across all three models for `debug=True`.
|
|
205
|
+
|
|
206
|
+
### 2. I/100L Normalization Metric
|
|
207
|
+
Introduced to eliminate the verbosity confound in cross-model security comparison:
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
I/100L = (Total Issues ÷ Lines of Code) × 100
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Without I/100L: GPT (17 issues) ≈ Claude (18 issues) — appears equal.
|
|
214
|
+
With I/100L: GPT (4.96) vs Claude (1.89) — reveals **2.6× density difference**.
|
|
215
|
+
|
|
216
|
+
### 3. FDSP K=1 Convergence
|
|
217
|
+
The engine was designed for up to K=3 iterations. All three models reached **zero High-severity findings at K=1** — 38 automated fixes in a single pass.
|
|
218
|
+
|
|
219
|
+
### 4. Temporal Audit
|
|
220
|
+
Seven major LLM security citations were mis-dated (2026 instead of 2025). Corrected dates documented in Chapter 2. The year 2026 represents **industrial adoption**, not discovery.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Prompt Catalog
|
|
225
|
+
|
|
226
|
+
All 20 tasks contained **zero security instructions** — measuring intrinsic model behavior only.
|
|
227
|
+
|
|
228
|
+
| ID | Framework | Primary CWE | Vulnerability Class |
|
|
229
|
+
|----|-----------|------------|-------------------|
|
|
230
|
+
| A01 | Python Flask | CWE-94, CWE-259 | debug=True, Hardcoded key |
|
|
231
|
+
| A02 | Python Flask | CWE-89, CWE-639 | SQL injection, IDOR |
|
|
232
|
+
| A03 | Python Flask | CWE-434, CWE-22 | Unrestricted upload, Path traversal |
|
|
233
|
+
| A04 | Python Flask | CWE-916, CWE-20 | Weak hashing, Input validation |
|
|
234
|
+
| A05 | Python Flask | CWE-89 | SQL injection via LIKE |
|
|
235
|
+
| A06 | Python Flask | CWE-285, CWE-330 | Broken access control |
|
|
236
|
+
| A07 | Python Flask | CWE-259, CWE-640 | Hardcoded credentials |
|
|
237
|
+
| A08 | Python Flask | CWE-22, CWE-200 | Path traversal, Info exposure |
|
|
238
|
+
| A09 | Python Flask | CWE-79, CWE-327 | XSS, Weak hash |
|
|
239
|
+
| A10 | Python Flask | CWE-78 | OS command injection / RCE |
|
|
240
|
+
| B01 | Node.js Express | CWE-345 | JWT algorithm confusion |
|
|
241
|
+
| B02 | Node.js Express | CWE-943 | NoSQL injection |
|
|
242
|
+
| B03 | Node.js Express | CWE-22 | Path traversal |
|
|
243
|
+
| B04 | Node.js Express | CWE-916 | Weak hashing |
|
|
244
|
+
| B05 | Node.js Express | CWE-89/943 | Injection via filter |
|
|
245
|
+
| B06 | Node.js Express | CWE-79 | Reflected XSS |
|
|
246
|
+
| B07 | Node.js Express | CWE-78 | OS command injection |
|
|
247
|
+
| B08 | Node.js Express | CWE-620 | Unverified password change |
|
|
248
|
+
| B09 | Node.js Express | CWE-918 | SSRF |
|
|
249
|
+
| B10 | Node.js Express | CWE-79 | Stored XSS |
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Tools & Scan Dates
|
|
254
|
+
|
|
255
|
+
| Tool | Version | Scope | Scan Date |
|
|
256
|
+
|------|---------|-------|-----------|
|
|
257
|
+
| Bandit | 1.9.4 | Python Flask (all 6 corpora) | 22 March 2026 |
|
|
258
|
+
| Semgrep | 1.155.0 | Node.js Express (all 6 corpora) | 25 March 2026 |
|
|
259
|
+
| FDSP Engine | 1.0 | Python (3 without-SHIELD corpora) | 6 April 2026 |
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Citation
|
|
264
|
+
|
|
265
|
+
```bibtex
|
|
266
|
+
@misc{idrees2026llmsecurity,
|
|
267
|
+
author = {Idrees, Ali Yasin},
|
|
268
|
+
title = {LLM Security in Web Applications: Emerging Threats,
|
|
269
|
+
Vulnerability Taxonomies, and Mitigation Frameworks},
|
|
270
|
+
year = {2026},
|
|
271
|
+
publisher = {GitHub},
|
|
272
|
+
url = {https://github.com/Aliidrees1234/llm-security-research}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Author
|
|
279
|
+
|
|
280
|
+
**Ali Yasin Idrees** — Independent Researcher, 2026
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
*This research was conducted independently, without institutional affiliation or external funding.*
|
|
285
|
+
*SHIELD Layer 4 is live and protecting this repository — every push is automatically scanned.*
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="shield-security",
|
|
5
|
+
version="0.5.0",
|
|
6
|
+
author="Ali Yasin Idrees",
|
|
7
|
+
author_email="aa1466805@gmail.com",
|
|
8
|
+
description="SHIELD — Automated security layer for LLM-assisted web development",
|
|
9
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
10
|
+
long_description_content_type="text/markdown",
|
|
11
|
+
url="https://github.com/Aliidrees1234/llm-security-research",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
install_requires=[
|
|
14
|
+
"bandit>=1.9.4",
|
|
15
|
+
"bcrypt>=4.0.0",
|
|
16
|
+
"colorama>=0.4.6",
|
|
17
|
+
"astor>=0.8.1",
|
|
18
|
+
],
|
|
19
|
+
extras_require={
|
|
20
|
+
"dev": [
|
|
21
|
+
"pytest>=7.0.0",
|
|
22
|
+
"semgrep",
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
entry_points={
|
|
26
|
+
"console_scripts": [
|
|
27
|
+
"shield=shield.cli:main",
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
python_requires=">=3.10",
|
|
31
|
+
classifiers=[
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
"Topic :: Security",
|
|
35
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
36
|
+
"Development Status :: 4 - Beta",
|
|
37
|
+
"Intended Audience :: Developers",
|
|
38
|
+
"License :: OSI Approved :: MIT License",
|
|
39
|
+
],
|
|
40
|
+
keywords=[
|
|
41
|
+
"security", "sast", "bandit", "semgrep",
|
|
42
|
+
"llm", "ai", "code-security", "vulnerability"
|
|
43
|
+
],
|
|
44
|
+
)
|