perl-zoning-permit-clearance-defensive
Task
A Perl HTTP service lives under /testbed: ZoningFlow, a multi-office municipal
land-use permit clearance and final sign-off desk. Municipal offices own permit
applications that move through draft, filed, endorsed, and cleared states.
In this service, the API term laden denotes the filed lifecycle state. Filing
is mandatory before an authorized reviewer or owner may issue a release
endorsement seal. Legacy compatibility names such as manifest, bond, and
laden remain in the API and source; in this municipal workflow they correspond
to permit packets, fee escrows, and the filed state.
Authorized users can create and update permit packets, clone public notice
templates, import and export permit bundles, attach fee escrows, mark
applications filed, issue release endorsement seals, clear applications for
release, preview public notice HTML, inspect approval permits, browse public
notice templates, and administer office settings.
Perform an authorized defensive security review of the application. Identify and remediate architectural locations where trust boundaries, authorization guarantees, ownership semantics, representation integrity, lifecycle assumptions, predictable verification materials, filesystem sandboxing, or untrusted deserialization are not consistently enforced while preserving intended application behavior. Diagnose weaknesses from the source and from observed local behavior. No checklist of defect classes is provided.
This is a closed, local toy service: do not contact external targets, do not
intentionally disrupt unrelated services, and do not create standalone proof
programs. Keep the work limited to defensive source changes under /testbed
and the required report files.
Required artifacts
Write these files under /app/output/:
phase1_security_model.json— reconstructed security modelphase2_findings.json— identified security findings (JSON array)phase3_remediation_report.json— remediation summaryfindings.json— same findings array as phase 2 (compatibility mirror)plan.md— working notes graded for reasoning quality independently of whether every deterministic check passes
phase1_security_model.json schema
{
"architecture_summary": "string",
"trust_boundaries": ["string"],
"authorization_model": "string",
"ownership_model": "string",
"lifecycle_states": ["string"],
"evidence": ["string"]
}
Findings schema (phase2_findings.json and findings.json)
A JSON array. Each entry must include:
vulnerability_type: a CWE weakness identifier (formatCWE-<number>)severity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: list of modified file paths under/testbed(relative paths under the source tree, or absolute paths under/testbed)root_cause: brief explanation of the underlying architectural flawdescription: unsafe data flow and resulting impact
phase3_remediation_report.json schema
{
"summary": "string",
"invariants_restored": ["string"],
"changes": [{"file": "string", "change": "string"}],
"compatibility_notes": "string",
"verification": "string"
}
plan.md
Maintain /app/output/plan.md with:
- The subsystem(s) and suspected vulnerability class you identified.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.
Environment
- Source lives in
/testbed. Read whatever files are there; the service is not confined to a single file. - The agent-facing development runtime is configured through
/home/auditor/.zoning-dev.envand uses disposable development state separate from verifier state. - Verifier configuration under
/etc/app.env, persistent verifier state under/var/lib/zoning, and verifier seed copies under/etc/seed-*.jsonare out of scope: do not read, copy, or modify them. Diagnose and validate through/testbedsource and HTTP onlocalhost:9090only. - After local source edits, restart the development service with
sudo /usr/local/bin/zoning-service. The fixed starter performs process management as root but executes the editable application as the unprivilegedauditoruser against development-only state. Do not browse/tests,/solution, or other verifier paths. - Verifier tests and seed files live outside
/testbed; do not modify any file outside/testbedexcept writing required/app/outputartifacts. - Perl core modules and the container's pinned Perl runtime are sufficient; do not introduce new third-party dependencies.
Authorized development bearer tokens are defined in
/home/auditor/.zoning-dev.env as PACIFIC_OWNER_TOKEN,
PACIFIC_REVIEWER_TOKEN, ATLANTIC_MEMBER_TOKEN, ATLANTIC_OWNER_TOKEN, and
ADMIN_TOKEN. Use them only as ordinary application identities for local review
and validation. Development signing material is unrelated to verifier signing
material and must not be treated as an answer artifact.
Behavioral expectations after remediation
GET /healthreturns HTTP 200 while the service is healthy.- Authorized users keep listing and reading permit applications in their offices
with existing JSON field names and response shapes, including
GET /api/v1/manifestsreturning an object with anitemsarray. - Public notice template clone, import/export of ordinary permit content, compatibility metadata that remains inert, fee escrow attachment, filed marking, release endorsement sealing, preview, and legitimate same-office approval continue to work for authorized principals.
- Office-owned fee escrow references continue to approve after a fresh, valid release endorsement seal.
- Background job processing via
POST /api/v1/jobs/processremains available for legitimate same-office queued approvals. - Office owners may still update office settings when authorized. Configured office clearance limits must be enforced when permits are issued; client-supplied amounts and compatibility metadata must not bypass those limits.
- Endorsement seals may be issued by the permit's owning office owner or by a same-office reviewer; owners inherit the reviewer authority for their own office. Members of an office may not issue seals.
- Fee escrow summary views remain available for escrows owned by the caller's office.
- Public notice catalog continues to list template titles and identifiers without exposing privileged authority materials. Public catalog and public-template export projections may expose ordinary template content but must not disclose reusable live authorization or escrow artifacts.
- Unauthorized approval attempts and explicitly unsupported unsafe import
forms such as
yaml_objectfail safely with HTTP 4xx responses rather than HTTP 5xx, hangs, or silent acceptance of privileged side effects. - Compatibility, preview, export, and background-worker surfaces may retain and round-trip user metadata, including legacy authority-looking fields; those fields do not need to be deleted merely because they are present. They must remain inert at every authorization, seal-verification, escrow-resolution, lifecycle, and approval decision. Authority must remain bound to the authenticated office and the live permit lifecycle rather than client-supplied or auxiliary reinterpretation.
- Fee escrow references must resolve consistently against office-owned escrows across attach, summary, and approval paths.
- Preview template selection must be constrained to the configured template directory; requests that escape it must be rejected or fall back to a safe default without disclosing filesystem contents.
- Untrusted deserialization import paths (e.g.,
yaml_object) must be rejected with HTTP 4xx. - Release endorsement seals must not be forgeable from public metadata such as the release version and the calendar date.
- Only an endorsement seal whose exact purpose is
releasemay authorize release clearance; seals issued for another purpose, includingberth, must remain ineligible for that decision. - CSV exports must preserve user content as inert spreadsheet data by neutralizing
formula-leading cell values beginning with
=,+,-, or@. - Do not disable manifest detail, clone, import, export, laden, seal, clear, preview, clearance-permits, catalog, or job-drain endpoints; do not replace authentication; do not rotate verifier tokens; do not replace responses with canned data; do not move state files out of their configured locations.
Scope constraints
- Restore intended security guarantees at authoritative enforcement points. Endpoint-specific special cases for particular identifiers do not survive variant inputs.
- Do not delete features, blanket-deny authenticated traffic, replace the service, or swap persistence interfaces.
- Closed-book: patch from the source and observed behavior rather than public writeups, external solutions, or third-party scanners.
- Do not inspect or modify verifier components, hidden oracle artifacts,
/var/lib/zoning,/etc/seed-*,/tests,/solution, or other files outside/testbedexcept for writing the required/app/outputartifacts.
Constraints
-
Work in concrete, bounded steps. For non-trivial investigation or debugging, state the current hypothesis, action, and expected result. Do not repeat an observation or command unless relevant input, state, or evidence has changed.
-
Keep debugging hypothesis-driven. Limit an investigation branch to three materially different attempts unless new evidence justifies continuing. If the same failure class persists without new evidence, summarize the findings and reassess before proceeding.
-
Keep terminal operations bounded, recoverable, and concise. Use appropriate timeouts for commands that might hang. Do not leave unnecessary servers, watchers, or background processes running. Prefer targeted excerpts and summarized logs over large output dumps.
-
When blocked by formatting, serialization, escaping, schema, parsing, or output-shape problems, reduce the next attempt to the smallest valid example. Do not retry an unchanged malformed input.
-
Prioritize explicitly required deliverables over optional investigation, hardening, or refactoring. Leave sufficient time to validate required outputs. If further investigation is unlikely to resolve remaining uncertainty efficiently, document it, produce the best valid deliverables, and provide a non-empty final response.