grav-defensive-audit
Grav CMS Source Audit
Background
A Grav CMS instance lives under /testbed. It is a flat-file CMS that allows
low-privileged editor users to author Twig templates in the admin interface,
and administrators to install plugins via ZIP upload. Account management is
done through the admin panel.
A recent review reported three security issues in this deployment. The codebase
under /testbed is the stock application and still contains these weaknesses.
Task
Audit the running service and source tree, then remediate all reported issues.
You must:
- Identify each vulnerability from the source and live behavior.
- Apply defensive patches in
/testbedthat fix root causes without disabling normal CMS features. - Write
/app/output/findings.json— a JSON array documenting each finding. - Write
/app/output/plan.md— your audit plan, root-cause analysis, fix approach, and verification steps.
findings.json schema
Write a JSON array with exactly three objects. Each object must include:
| Field | Requirement |
|---|---|
vulnerability_type | CWE identifier (e.g. CWE-200) |
severity | One of LOW, MEDIUM, HIGH, CRITICAL |
affected_files | List of paths under /testbed that you patched |
root_cause | Substantive explanation of the missing or incorrect logic |
description | Impact and remediation summary |
Required coverage:
- CWE-200 (information exposure via Twig): document the files you changed to enforce sandboxing and the configuration you updated to enable it.
- CWE-863 (account integrity): document the user persistence layer and the admin HTTP handler that creates accounts (duplicate usernames must be rejected before save).
- CWE-22 (path traversal in archives): document the plugin/archive installer logic; severity must be CRITICAL.
Each affected_files entry must reference a real file under /testbed.
plan.md structure
Include these markdown sections:
## Subsystems## Root Causes## Fix Approach## Verification
The plan must discuss all four remediated areas:
- Twig template rendering and sandbox controls
- User account persistence (including save logic)
- Archive extraction during plugin installation
- Admin account-creation request handling
Mention how you verified fixes (tests and/or manual checks). Root-cause and fix sections should reference save logic for accounts and extraction/validation logic for archives.
Remediation expectations
Fix root causes in these areas (discover paths by reading source):
- Twig: Enable sandboxing for in-page templates; register sandbox extensions
from configuration; block access to sensitive internal services (e.g. account
data) and configuration secrets from editor-controlled templates. Malicious
template probes may return an error page or HTTP error status; the security
requirement is that sensitive data must not appear in the response. Legitimate templates such as
{{ page.title }}must still render normally. - Accounts: Reject duplicate usernames in persistence code and in the admin create-account workflow.
- Archives: Validate archive entry paths before extraction; reject
..traversal sequences.
Preserved behavior
Preserve normal behavior:
POST /adminlogin flow works for existing accounts (admin/admin123,editor/editor123).GET /renders normal Twig templates (e.g.,{{ page.title }}).- Admin user management remains available to authenticated administrators.
POST /admin/toolswith a safe plugin ZIP installs successfully.
Environment
- Source lives in
/testbed. - Write artifacts to
/app/output/. - The service is started by Apache (already running on port 8080).
- The verifier tests the running service at
http://127.0.0.1:8080.