id: website-sensitive-file-exposure-audit
namespace: company.team
description: |
Probe your own websites for files that should never be public: an exposed `.git` directory, `.env`
files, cloud credentials, database dumps, Spring Boot actuator or PHP info pages, and directory
listings. Each check matches the file's content, not just the status code, so soft-404 pages do not
raise false alarms. New exposures and fixes are posted to Slack.
inputs:
- id: sites
type: JSON
displayName: Sites to audit
description: List of objects with a base URL you own and an owner to mention.
defaults: |
[
{"url": "https://www.example.com", "owner": "@web-team"}
]
- id: timeout_seconds
type: INT
displayName: Request timeout (seconds)
defaults: 10
tasks:
- id: for_each_site
type: io.kestra.plugin.core.flow.Loop
description: Audit every site independently, two at a time to stay gentle on the
servers.
values: "{{ inputs.sites }}"
concurrencyLimit: 2
tasks:
- id: load_previous
type: io.kestra.plugin.core.kv.Get
description: Exposures reported at the last run. Missing on the first run.
key: "exposure_audit_{{ fromJson(item.value).url | slugify }}"
errorOnMissing: false
- id: probe
type: io.kestra.plugin.scripts.python.Script
description: Request each well-known sensitive path and confirm a finding only
when the content matches.
containerImage: python:3.12-slim
inputFiles:
site.json: "{{ item.value }}"
previous.json: "{{ (outputs.load_previous.value ?? {}) | toJson }}"
script: |
import json
import re
import urllib.error
import urllib.request
from datetime import datetime, timezone
def load(name):
with open(name, encoding="utf-8") as f:
data = json.load(f)
return json.loads(data) if isinstance(data, str) else data
site = load("site.json")
previous = load("previous.json") or {}
base = site["url"].rstrip("/")
# (path, severity, what it exposes, content check on the first 64 KB)
CHECKS = [
("/.git/HEAD", "critical", "Git repository: the full source history can be downloaded",
lambda b: re.match(rb"^(ref: refs/|[0-9a-f]{40}\s*$)", b)),
("/.git/config", "critical", "Git config, often with the remote URL and credentials",
lambda b: b"[core]" in b),
("/.env", "critical", "Environment file with secrets",
lambda b: len(re.findall(rb"(?m)^[A-Z][A-Z0-9_]{2,}=", b)) >= 2),
("/.aws/credentials", "critical", "AWS access keys",
lambda b: b"aws_access_key_id" in b.lower()),
("/backup.sql", "critical", "Database dump",
lambda b: re.search(rb"(CREATE TABLE|INSERT INTO)", b, re.I)),
("/dump.sql", "critical", "Database dump",
lambda b: re.search(rb"(CREATE TABLE|INSERT INTO)", b, re.I)),
("/wp-config.php.bak", "critical", "WordPress config backup with database password",
lambda b: b"DB_PASSWORD" in b),
("/actuator/env", "high", "Spring Boot actuator environment (configuration and secrets)",
lambda b: b"propertySources" in b),
("/phpinfo.php", "high", "phpinfo() page with server configuration",
lambda b: b"PHP Version" in b and b"phpinfo" in b.lower()),
("/server-status", "high", "Apache server-status with live requests and client IPs",
lambda b: b"Apache Server Status" in b),
("/.DS_Store", "medium", "macOS folder index that lists file names",
lambda b: b[4:8] == b"Bud1"),
("/", "medium", "Directory listing",
lambda b: re.search(rb"<title>\s*(Index of /|Directory listing for /)", b, re.I)),
]
def fetch(path):
req = urllib.request.Request(base + path, headers={
"User-Agent": "kestra-exposure-audit (authorized self-check)", "Range": "bytes=0-65535"})
try:
with urllib.request.urlopen(req, timeout={{ inputs.timeout_seconds }}) as r:
return r.status, r.read(65536)
except urllib.error.HTTPError as e:
return e.code, b""
findings = {}
reachable = False
for path, severity, what, matches in CHECKS:
try:
status, body = fetch(path)
except Exception as e:
print(f"{path}: unreachable ({e.__class__.__name__})")
continue
reachable = True
if status in (200, 206) and matches(body):
findings[path] = f"*{severity}* `{base}{path}`: {what}."
try:
status, body = fetch("/.well-known/security.txt")
m = re.search(rb"(?im)^Expires:\s*(\S+)", body) if status in (200, 206) else None
if m:
expires = datetime.fromisoformat(m.group(1).decode().replace("Z", "+00:00"))
if expires < datetime.now(timezone.utc):
findings["security.txt"] = f"*low* `{base}/.well-known/security.txt` expired on {expires.date()} (RFC 9116), so researchers may ignore it."
except Exception:
pass
if not reachable:
raise SystemExit(f"{base} could not be reached at all; check the URL.")
new = [findings[k] for k in findings if k not in previous]
resolved = [previous[k] for k in previous if k not in findings]
print(f"{base}: {len(findings)} exposures ({len(new)} new, {len(resolved)} resolved)")
print("::" + json.dumps({"outputs": {
"new": new,
"resolved": resolved,
"notify": bool(new or resolved),
"critical": any("*critical*" in f for f in new),
"findings": findings,
}}) + "::")
- id: if_changed
type: io.kestra.plugin.core.flow.If
description: Only post when an exposure appears or is fixed.
condition: "{{ outputs.probe.vars.notify }}"
then:
- id: alert_owner
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post the confirmed exposures and the fixed ones.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
{{ outputs.probe.vars.critical ? ':rotating_light:' : (outputs.probe.vars.new | length > 0 ? ':warning:' : ':white_check_mark:') }} *Sensitive file audit: {{ fromJson(item.value).url }}* (owner: {{ fromJson(item.value).owner }})
{% for f in outputs.probe.vars.new %}- {{ f }}
{% endfor %}{% for f in outputs.probe.vars.resolved %}- Fixed: {{ f }}
{% endfor %}{{ outputs.probe.vars.new | length > 0 ? 'Block the path at the web server or CDN, then rotate any secret it contained: assume it has already been copied.' : '' }}
- id: remember_findings
type: io.kestra.plugin.core.kv.Set
description: Store the current exposures so each one is posted once. Runs after
the alert.
key: "exposure_audit_{{ fromJson(item.value).url | slugify }}"
kvType: JSON
overwrite: true
value: "{{ outputs.probe.vars.findings | toJson }}"
errors:
- id: alert_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: A site that cannot be audited must not look clean.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: ":warning: Sensitive file audit failed in execution {{ execution.id
}} ({{ flow.namespace }}.{{ flow.id }}). Open the failed loop iteration:
the site may be down or the URL wrong."
triggers:
- id: daily
type: io.kestra.plugin.core.trigger.Schedule
description: A bad deploy can expose files at any time; check daily. Disabled
until the Slack secret is set.
cron: "0 5 * * *"
disabled: true