Skip to main content

LLM Security in Web Applications

Emerging Threats, Vulnerability Taxonomies, and Mitigation Frameworks

Independent Academic Research — Ali Yasin Idrees — 2026

SHIELD Security Gate Python Version Tests


Overview

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.

Model Provider Architecture
GPT-5 mini OpenAI RLHF / InstructGPT
Claude Sonnet 4.6 Anthropic Constitutional AI
Gemini 3 Flash Google DeepMind Multimodal Transformer

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.


Key Findings

  • 52 security findings across 60 generated files — zero files were completely clean
  • debug=True (CWE-94) present in 27 of 30 Flask files across all three models
  • Knowledge-Action Gap confirmed at 100% — all models warned against vulnerabilities they simultaneously generated
  • 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
  • SHIELD Layer 3 FDSP eliminated 100% of High-severity findings at K=1 across all models — 38 auto-remediations in a single automated pass

I/100L Vulnerability Density — All Conditions

Condition GPT-5 mini Claude S.4.6 Gemini 3 Flash Average
Without SHIELD 4.96 1.89 6.00 4.28
With SHIELD Layer 1 1.44 1.02 1.02 1.16
With SHIELD Layer 3 1.16 0.17 ⭐ 1.55 0.96
Total Reduction 77% 91% 74% 77% avg

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.


SHIELD Framework

Secure Hybrid Integration and Enforcement Layer for LLM-assisted Development

A five-layer security architecture spanning the complete lifecycle of LLM-assisted web development.

┌──────┬──────────────────────────┬──────────────────────────────┐
│  L1  │  Prompt Engineering      │  SPT — 9 mandatory rules     │
│  L2  │  Generation Guidance     │  GRASP DAG — 8 SCP nodes     │
│  L3  │  Validation & Remediation│  FDSP — K=3 auto-fix engine  │
│  L4  │  Deployment Gate         │  GitHub Actions CI/CD        │
│  L5  │  Runtime Monitoring      │  WAF + Canary + JIT perms    │
└──────┴──────────────────────────┴──────────────────────────────┘
Layer File Status
Layer 1 Built into prompts ✅ Empirically Validated
Layer 2 shield/layer2_grasp.py ✅ CLI Integrated — shield prompt
Layer 3 shield/layer3_fdsp.py ✅ Empirically Validated — shield fix
Layer 4 .github/workflows/shield_layer4_gate.yml ✅ Live CI/CD gate
Layer 5 shield/layer5_runtime.py ✅ CLI Integrated — shield monitor

Repository Structure

llm-security-research/
│── .github/workflows
|     ├──shield_layer4_gate.yml
├── shield/                   
│   ├── cli.py
│   ├── reporter.py
│   ├── config.py
│   ├── layer2_grasp.py
│   ├── layer3_fdsp.py
│   ├── layer5_runtime.py
│   └── rules/
│       └── custom_rules.py
│
├── research/                  ← all research data
│   ├── paper/
│   ├── snippets/
│   └── results/
│
├── tests/                     ← all tests
├── docs/                      ← NEW: documentation
│   ├── rules.md               ← explain every rule
│   ├── pipeline.md            ← explain L2+L3 flow
│   └── api.md                 ← developer API reference
│
├── examples/                  ← NEW: real usage examples
│   ├── flask_login.py         ← vulnerable → fixed demo
│   └── node_download.js       ← vulnerable → fixed demo
│
├── setup.py
├── README.md


Running the SHIELD Tools

Installation

git clone https://github.com/Aliidrees1234/llm-security-research
cd llm-security-research
pip install -e .

Usage

# Scan a project
shield scan ./my_project

# Scan with HTML report
shield scan ./my_project --report report.html

# Scan quietly (High/Medium only)
shield scan ./my_project --quiet

# Auto-fix vulnerabilities
shield fix ./project` | Auto-fix Python vulnerabilities (Python only) |
shield fix ./my_project --output ./fixed --k 3

# Fix with report
shield fix ./my_project --output ./fixed --report after.html

# Compare before and after
shield compare before.json after.json --report comparison.html

# Initialize config file
shield init

# Show version
shield version

# Show doctor
shield doctor` | Check all dependencies and installation health |

# Full pipeline — prompt → generate → scan → fix
shield secure "Write a Flask login endpoint with SQLite"

# Secure prompt 
shield secure "Write a Flask login endpoint"

# Runtime monitor self-test
shield monitor --test

# Show WAF rules
shield monitor --show-rules

# Show shield dashboard
shield dashboard

## Security Auditing
# Generate Audit
shield audit ./project --company "Acme BV"` | Generate professional client audit report 

SHIELD can generate professional audit reports suitable for client engagements.


```bash
# Basic audit
shield audit ./my_project --company "Acme BV"

# Full audit with custom auditor name and output file
shield audit ./my_project \
  --company "Acme BV" \
  --auditor "Ali Yasin Idrees" \
  --output acme_audit_2026.html

# Open the report
start acme_audit_2026.html

The audit report includes:

  • Executive summary with security grade
  • Overall risk level (Low / Medium / High / Critical)
  • I/100L vulnerability density score
  • All findings with file, line, CWE reference, and remediation advice
  • Remediation priority table
  • Automated fix instructions

Suitable for delivering to clients as a standalone confidential document.

Language Support:

  • shield fix — Python only (AST-based auto-remediation)
  • shield scan — 8 languages (Python, JS, TS, C#, Java, PHP, Go, Ruby)
  • shield audit — 8 languages (professional report for any language)

Multi-language auto-fix is planned for a future release.

Run Tests

pip install pytest
pytest tests/ -v
# 99 tests passing

Layer 2 — GRASP DAG (Prompt Enhancer)

Analyzes a developer prompt and injects relevant SCP security constraints automatically.

from shield_layer2_grasp import GRASPEngine

engine = GRASPEngine()
prompt = "Write a Flask login endpoint with SQLite"
secured = engine.build_secured_prompt(prompt)
# Send secured to your LLM instead of the raw prompt
---
# Generate security-hardened prompt for any LLM
shield prompt "Write a Flask login endpoint"

# Copy directly to clipboard
shield prompt "Write a Flask login endpoint" --copy

Layer 3 — FDSP Auto-Remediation

pip install bandit

python shield_layer3_fdsp.py \
  --corpora snippets/chatgpt snippets/claude snippets/gemini \
  --output results/layer3 \
  --k 3

Actual results from this study (April 6, 2026):

Corpus          K0 High   K1 High   K0 I/100L   K1 I/100L   Reduction
chatgpt/           11         0        3.30         1.16        100%
claude/            11         0        1.50         0.17        100%
gemini/             9         0        4.42         1.55        100%

Layer 5 — Runtime Monitoring

from flask import Flask
from shield_layer5_runtime import ShieldMiddleware

app = Flask(__name__)
shield = ShieldMiddleware(app, block_injections=True)
# Now protects against prompt injection, canary detection, JIT permissions

Research Contributions

1. Knowledge-Action Gap (Definition 2.1)

The first formal definition of the phenomenon where LLMs warn against vulnerabilities they simultaneously generate:

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.

Confirmed at 100% rate across all three models for debug=True.

2. I/100L Normalization Metric

Introduced to eliminate the verbosity confound in cross-model security comparison:

I/100L = (Total Issues ÷ Lines of Code) × 100

Without I/100L: GPT (17 issues) ≈ Claude (18 issues) — appears equal. With I/100L: GPT (4.96) vs Claude (1.89) — reveals 2.6× density difference.

3. FDSP K=1 Convergence

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.

4. Temporal Audit

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.

5. Supply Chain Attack Detection (2026)

Two new rules targeting the 2026 wave of registry poisoning attacks:

  • CUSTOM_UNICODE_OBFUSCATION — detects zero-width Unicode characters (TrapDoor campaign)
  • CUSTOM_INSTALL_EXEC — detects module-level execution at import time

Prompt Catalog

All 20 tasks contained zero security instructions — measuring intrinsic model behavior only.

ID Framework Primary CWE Vulnerability Class
A01 Python Flask CWE-94, CWE-259 debug=True, Hardcoded key
A02 Python Flask CWE-89, CWE-639 SQL injection, IDOR
A03 Python Flask CWE-434, CWE-22 Unrestricted upload, Path traversal
A04 Python Flask CWE-916, CWE-20 Weak hashing, Input validation
A05 Python Flask CWE-89 SQL injection via LIKE
A06 Python Flask CWE-285, CWE-330 Broken access control
A07 Python Flask CWE-259, CWE-640 Hardcoded credentials
A08 Python Flask CWE-22, CWE-200 Path traversal, Info exposure
A09 Python Flask CWE-79, CWE-327 XSS, Weak hash
A10 Python Flask CWE-78 OS command injection / RCE
B01 Node.js Express CWE-345 JWT algorithm confusion
B02 Node.js Express CWE-943 NoSQL injection
B03 Node.js Express CWE-22 Path traversal
B04 Node.js Express CWE-916 Weak hashing
B05 Node.js Express CWE-89/943 Injection via filter
B06 Node.js Express CWE-79 Reflected XSS
B07 Node.js Express CWE-78 OS command injection
B08 Node.js Express CWE-620 Unverified password change
B09 Node.js Express CWE-918 SSRF
B10 Node.js Express CWE-79 Stored XSS

Tools & Scan Dates

Tool Version Scope Scan Date
Bandit 1.9.4 Python Flask (all 6 corpora) 22 March 2026
Semgrep 1.155.0 Node.js Express (all 6 corpora) 25 March 2026
FDSP Engine 1.0 Python (3 without-SHIELD corpora) 6 April 2026

Citation

@misc{idrees2026llmsecurity,
  author    = {Idrees, Ali Yasin},
  title     = {LLM Security in Web Applications: Emerging Threats,
               Vulnerability Taxonomies, and Mitigation Frameworks},
  year      = {2026},
  publisher = {GitHub},
  url       = {https://github.com/Aliidrees1234/llm-security-research}
}

Author

Ali Yasin Idrees — Independent Researcher, 2026


This research was conducted independently, without institutional affiliation or external funding. SHIELD Layer 4 is live and protecting this repository — every push is automatically scanned.

Metadata

Release files for shield-security 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shield-security 1.0.6
File Size Uploaded Provenance
shield_security-1.0.6.tar.gz 60.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for shield-security 1.0.6
File Interpreter ABI Platform
shield_security-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 118.7 kB

Release files / shield_security-1.0.6.tar.gz

Download URL shield_security-1.0.6.tar.gz
Size 60.9 kB
Tags Source
SHA-256 checksum
How to use checksums
42bd22db185b9960d8fc8db9bc9b3a620318fa882e21c0daefc274f9b335a10d
BLAKE2b-256 checksum
How to use checksums
20c5b852cf14ba52ef3f78d46aae15c73008048a56f564126c32b26dac8dd019
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / shield_security-1.0.6-py3-none-any.whl

Download URL shield_security-1.0.6-py3-none-any.whl
Size 57.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
374fe84a85c850495e754fcad49c9e44a47b4d5267443e43c0d2a24baee1329e
BLAKE2b-256 checksum
How to use checksums
fa4cd8dc1952ce18e2d951e59cb537aba1e19374fd486ba1c949f79798d9bd17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for shield-security 1.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page