from jinja2 import Template
from flask import request
def render_page():
user_input = request.args.get('template')
template = Template(user_input) # VULNERABLE!
return template.render()
Real vulnerable code examples with actual detection output. Every example below has been tested and verified to work.
from jinja2 import Template
from flask import request
def render_page():
user_input = request.args.get('template')
template = Template(user_input) # VULNERABLE!
return template.render()
from flask import request, render_template
def render_page():
user_name = request.args.get('name')
# Use predefined template file
return render_template('page.html', name=user_name)
Server-Side Template Injection allows attackers to execute arbitrary code on your server. An attacker could send a malicious template like {{config.__class__.__init__.__globals__['os'].popen('ls').read()}} to run system commands.
Real-world impact: Complete server takeover, data theft, ransomware deployment.
import sqlite3
from flask import request
def get_user():
user_id = request.args.get('id')
conn = sqlite3.connect('db.sqlite')
cursor = conn.cursor()
query = f"SELECT * FROM users WHERE id = {user_id}"
cursor.execute(query) # VULNERABLE!
return cursor.fetchone()
def get_user():
user_id = request.args.get('id')
conn = sqlite3.connect('db.sqlite')
cursor = conn.cursor()
# Use parameterized query
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
return cursor.fetchone()
SQL injection allows attackers to manipulate database queries. With input like 1 OR 1=1, attackers can bypass authentication or extract entire databases.
Real-world impact: Data breaches, authentication bypass, data deletion.
import subprocess
from flask import request
def list_files():
directory = request.args.get('dir')
# shell=True makes this vulnerable!
result = subprocess.run(f"ls {directory}", shell=True)
return result
def list_files():
directory = request.args.get('dir')
# Use list of arguments, no shell=True
result = subprocess.run(['ls', directory],
capture_output=True,
text=True)
return result.stdout
Command injection allows attackers to execute arbitrary system commands. Input like ; rm -rf / could delete your entire filesystem.
Real-world impact: Complete system compromise, ransomware, cryptocurrency mining.
import requests
# Stripe API key hardcoded in source code
API_KEY = "sk_live_51HqT2KLm9N8pQr3X4vY5zW6aB7cD8eF"
def charge_customer(amount):
headers = {"Authorization": f"Bearer {API_KEY}"}
return requests.post("https://api.stripe.com/v1/charges",
headers=headers)
import os
import requests
# Load from environment variable
API_KEY = os.getenv('STRIPE_API_KEY')
def charge_customer(amount):
if not API_KEY:
raise ValueError("STRIPE_API_KEY not configured")
headers = {"Authorization": f"Bearer {API_KEY}"}
return requests.post("https://api.stripe.com/v1/charges",
headers=headers)
Hardcoded secrets end up in version control (Git), CI/CD logs, and production deployments. Anyone with access to your code can use these credentials.
Real-world impact: Unauthorized API charges ($$$), account takeover, data breaches.
100% detection accuracy
87% test pass rate
75% coverage
Safe code not flagged
Real scan results from examples/showcase_examples.py
| Rule Type | Detections | Test Status | Example |
|---|---|---|---|
| TEMPLATE_INJECTION | 3 found | ✓ Tested | Jinja2, Mako templates |
| HARDCODED_SECRET | 3 found | ✓ Tested | API keys, passwords |
| WEAK_CRYPTO | 3 found | ✓ Tested | MD5, SHA1 usage |
| COMMAND_INJECTION | 2 found | ✓ Tested | os.system, subprocess |
| DANGEROUS_EXEC | 2 found | ✓ Tested | eval(), exec() |
| INSECURE_RANDOM | 2 found | ✓ Tested | random module tokens |
| LOG_INJECTION | 2 found | ✓ Tested | Unescaped logging |
| SQL_INJECTION | 1 found | ✓ Tested | String concatenation |
| SSRF | 1 found | ✓ Tested | User-controlled URLs |
| PATH_TRAVERSAL | 1 found | ✓ Tested | File path concat |
| XXE | 1 found | ✓ Tested | Unsafe XML parsing |
| TIMING_ATTACK | 1 found | ✓ Tested | String comparison |
| OPEN_REDIRECT | 1 found | ✓ Tested | Unvalidated redirect |
| INSECURE_DESERIALIZATION | 1 found | ✓ Tested | pickle.loads() |
| BARE_EXCEPT | 1 found | ✓ Tested | Empty except clause |
| DEBUG_CODE | 1 found | ✓ Tested | breakpoint() |
git clone https://github.com/tonybowen-me/Mikmbr.gitpip install -e .mikmbr scan examples/showcase_examples.pyexamples/scan_results.jsonpytest tests/test_rule_matrix.py -vEverything is publicly verifiable. No hidden test data.
We test that rules detect vulnerable code:
# Vulnerable code
result = eval(user_input)
# Mikmbr detects ✓
assert len(findings) == 1
We test that rules don't flag safe code:
# Safe code
result = ast.literal_eval(data)
# Mikmbr ignores ✓
assert len(findings) == 0
All test code is publicly available on GitHub
View Test Code →Every detection is tested and verified. All results are reproducible.