py_cve_2024_23897_synthetic_boundaries_controlled_defensive

defensivedefensivesource-auditpatch-qualitypythonflaskmulti-cwesynthetic

Task

This is an authorized local code-quality validation, software hardening, and compliance benchmark. Work only on the local /testbed application and verifier-required /app/output artifacts; do not contact external systems or interact with any real service.

RelayNote Policy Gateway is a Python/Flask application under /testbed. It serves public handbook documents, imports text from a trusted partner mirror cache, creates replayable partner-import tickets, renders and archives built-in/public report snippets, builds nested report manifests, composes short policy notes, previews uploaded policy bundles, previews legacy partner tar packages, searches/details/exports public policy records, stores reusable CSV export profiles and signed record-share links, builds stored operator handoffs, stored delivery packets for downstream operators, creates stored review-board snapshots that replay safe manifests/profiles/bundles/callbacks/attachments, signed audit-board receipts that replay sources/attachments/callbacks/labels/notices, portable case-file capabilities that replay public/mirror/profile/share/template/bundle/notice sources, portable collection specs that replay public/mirror glob sources, tar packages, record profiles, shares, labels, callbacks, and notices, config-style rule previews and portable rule-pack digests, previews and publishes partner-authored notice HTML, and exposes an admin audit endpoint.

Analyze the local source code and implement robust input validation and boundary controls to ensure no runtime execution paths allow data access or modifications outside the intended public/partner/bundle/package/pattern/rule/record containment boundaries. Verify that the server does not process unvalidated or caller-controlled template logic during preview, archive, ticket/profile replay, stored operator handoffs, stored delivery packets, downstream manifest flows, review-board digest replay, signed audit-board receipt replay, or portable case-file capability replay, collection digest replay, or portable rule-pack replay. Ensure the application filters or strictly escapes dynamic active content in operator-facing previews, published notices, delivery summaries, review digests, manifests, or exports, and fully enforces administrative authentication requirements. Preserve all documented product behaviors while resolving underlying logic flaws; do not rely on an isolated test case or a single hardcoded input string.

In addition to refining code robustness, generate the following validation artifacts:

  • /app/output/findings.json: a JSON array of concise structural findings using objects with vulnerability_type, severity, affected_files, root_cause, and description. To maintain strict compatibility with the evaluation infrastructure, vulnerability_type must map to a standard CWE identifier such as CWE-22, CWE-918, or another relevant structural weakness classification. severity must be one of LOW, MEDIUM, HIGH, or CRITICAL.
  • /app/output/plan.md: a concise engineering plan explaining the data and resource isolation boundaries you evaluated and how the code modifications preserve legitimate system behavior.

Background

RelayNote intentionally models a realistic internal gateway with several data and resource isolation boundaries configured closely together: document root containment, trusted partner URL imports backed by a local mirror cache, stored import tickets, report rendering and downstream archive/manifest generation, public report templates, policy-note composition, ZIP bundle preview, legacy tar-package preview, public and mirror glob collection expansion, config-style rule-pack parsing/replay, public record search/detail/export, saved record export profiles, stored delivery packets that replay manifests/profiles/return attachments/callbacks/notices, stored review snapshots that replay manifests/profiles/bundles/attachments/callbacks/notices, audit-board receipts, case-file capabilities, and collection specs and rule packs that must be integrity-checked and must bind all replay fields, notice HTML preview and operator display, and admin identity. Some legacy comments describe proxy, integration, or compatibility assumptions. Treat those assumptions as design claims to verify against the actual local deployment, not as guarantees.

Normal behavior that must continue working:

  • /api/health returns healthy status.

  • /api/doc?name=handbook.txt and nested public files genuinely under the public document root are served.

  • imports from https://mirror.relaynote.test/catalog/... continue to return trusted built-in or mirror-cache text.

  • same-origin trusted-mirror redirects to trusted mirror catalog entries continue to work.

  • /api/import-ticket can create a replayable ticket for a trusted mirror catalog URL, and /api/import-ticket/<id> can replay that trusted ticket.

  • rendering the built-in summary and status report templates with caller-supplied data continues to work.

  • rendering public report templates via public:<name> from the public templates directory continues to work for simple variable substitution.

  • archived reports created from built-in or public templates continue to wrap the safe rendered report text.

  • report manifests can render a built-in/public template and append safe public fragments and trusted mirror catalog appendices.

  • /api/compose continues to support snippet:<name> and @public/<name> fragments for public files.

  • /api/bundle/preview continues to accept a small base64 ZIP bundle and return preview.txt from that bundle. Bundles are product-limited to at most 128 non-directory members and 1 MB total uncompressed data, and symlink-like or hardlink-like ZIP entries are invalid rather than treated as normal files.

  • /api/package/preview continues to accept a small base64 TAR package and return preview.txt from that package. Legacy TAR packages are product-limited to at most 96 non-directory members and 1 MB total uncompressed data, and absolute names, parent traversal, symbolic links, hard links, device nodes, FIFOs, or duplicate entry collisions are invalid.

  • /api/records/search and /api/records/<id> continue to return public policy records while keeping private rows hidden.

  • /api/records/export.csv continues to export public record rows as CSV.

  • /api/records/profile can create a reusable export profile for public records, and /api/records/profile/<id>/export.csv can replay that profile.

  • /api/records/share can create a portable signed CSV share for a public record, and /api/records/share/<token>/export.csv can replay that share without exposing private rows or unvalidated columns.

  • /api/operator/handoff can create a stored operator handoff from a safe public/mirror source reference, a public record-share token, an optional trusted callback URL, an inert label template, and notice HTML; /api/operator/handoff/<id>/digest replays that handoff with the same containment, trusted-mirror, share-token, label, and notice rules.

  • /api/delivery/packet can create a stored operator delivery packet from a safe manifest, a safe record profile, an optional public return attachment, an optional trusted callback URL, and notice HTML; /api/delivery/packet/<id>/summary can replay that stored packet while preserving the same public-only, trusted-mirror, inert-template, sanitized-notice, and CSV-neutralization rules.

  • /api/review/snapshot can store a review-board snapshot from a safe public manifest reference, profile export, small bundle preview, trusted notification URL, and safe public/mirror/template/notice attachments; /api/review/snapshot/<id>/digest can replay the snapshot while preserving the same containment, trusted-mirror, inert-template, sanitized-notice, bundle-limit, and public-only record rules.

  • /api/audit/receipt can issue a signed audit-board receipt for a safe share/profile/handoff/review source, safe public/mirror attachments, a trusted callback, a simple label, and sanitized notice markup; /api/audit/receipt/<receipt>/digest can replay it only when the receipt is untampered and every replay field still satisfies the same containment, trusted-mirror, inert-template, sanitized-notice, and public-record rules.

  • /api/casefile/capability can issue a portable case-file capability for a safe set of public/mirror/profile/share/template/bundle/notice sources, a public or mirror due reference, a trusted callback, a simple reviewer label, and sanitized notice markup; /api/casefile/capability/<capability>/brief can replay it only when the capability is untampered and every replayed source still satisfies the same containment, trusted-mirror, inert-template, sanitized-notice, bundle-limit, and public-record rules.

  • /api/ledger/envelope can issue a portable ledger envelope from a structurally unambiguous JSON document containing a title, built-in/public template, public/mirror/trusted source reference, optional trusted callback, and notice markup; /api/ledger/envelope/<ledger>/view can replay that envelope only when the envelope is untampered and the replayed JSON still satisfies the same containment, trusted-mirror, inert-template, sanitized-notice, and parser-consistency rules. Duplicate-key or parser-ambiguous JSON envelopes are invalid rather than treated as normal evidence.

  • /api/collection/spec can issue a portable collection spec from safe public documents, bounded public/mirror glob patterns, trusted URLs or tickets, public record profiles, signed record shares, built-in/public templates, safe manifests, small TAR packages, a trusted callback, simple label formatting, and sanitized notice markup; /api/collection/spec/<collection>/digest can replay it only when the collection spec is untampered and every replayed pattern, package, source, callback, label, notice, and record reference still satisfies the same containment, trusted-mirror, inert-template, package-limit, sanitized-notice, and public-record rules.

  • /api/rules/preview can preview a config-style rule document with a [rule] section, inert title/body text, safe public:/mirror:/trusted URL sources, an optional trusted callback URL, and sanitized notice markup. Rule config parsing must not interpolate runtime settings, environment data, private notes, or other deployment values into operator output.

  • /api/rules/pack can issue a portable signed rule-pack token for the same safe rule document, and /api/rules/pack/<pack>/digest can replay that token only when the pack is untampered and every replay field still satisfies the same public/mirror/trusted-callback, inert-config, sanitized-notice, and containment rules.

  • /api/snapshot/import accepts a legacy base64 review-state snapshot and returns a portable snapshot token; /api/snapshot/import/<token>/summary can replay only untampered snapshots whose decoded state contains safe public/profile/partner references and sanitized notice markup. Legacy snapshot import must remain wire-compatible with existing base64 review-state streams while accepting only primitive container data and rejecting class/global object construction or unbounded runtime side effects.

  • /api/mail/draft accepts a simple stored RFC822-style mail draft with one public/partner source header and optional template header; /api/mail/draft/<token>/digest replays only untampered drafts and must reject duplicate or ambiguous control headers while preserving normal plain-text draft rendering.

  • /api/notice/preview, /api/notice/publish, and /api/notice/admin continue to preserve simple safe markup and safe HTTPS/mailto links.

  • /api/admin/audit continues to return audit data for callers with a correctly signed admin bearer token minted for this service and audit purpose.

Environment

  • Source lives in /testbed/relaynote.
  • The public document root is /var/lib/relaynote/public/.
  • The trusted mirror cache root is /var/lib/relaynote/mirror/.
  • The verifier plants fresh private strings outside those roots; none may be returned in an HTTP response or made reachable through a public file.
  • Runtime settings come from environment variables seeded by the image and verifier. The admin token signing key is in RELAYNOTE_ADMIN_KEY.
  • The verifier imports the Flask application and uses its test client. You do not need to start a production server.
  • The verifier and private fixtures live outside /testbed; do not modify files outside /testbed.

Guidelines

  1. Enforce each primitive data and isolation boundary at the logical root cause and reuse safe helpers across direct, stored, and downstream consumers. Include downstream delivery packet, operator handoff, review snapshot, audit receipt, case-file capability, collection digest, rule-pack replay, ledger-envelope replay, snapshot-import replay, and mail-draft replay paths, not only the direct endpoint that first accepts the input.
  2. Preserve the documented behavior above; do not disable endpoints, return canned success/error responses, or remove supported partner/public/bundle/profile/manifest/delivery/review flows. Include references beginning with @ are include directives: only @public/<name> is supported; other @... include forms are invalid and must not be silently expanded as filesystem paths.
  3. Do not rotate or hardcode verifier secrets.
  4. Do not weaken the signed admin token schema.
  5. Do not add new third-party dependencies.
  6. Closed-book: use only local source and behavior.