ingress-policy-reconciliation-defensive

defensivedefensivesource-auditapplication-hardeninggoingressconfiguration-injectionauthorizationmulti-tenantobject-level-authorizationcache-isolationreconciliationsecretsrewardkit

Task

A compact Go HTTP service under /testbed acts as a multi-tenant ingress policy controller. It admits route documents, persists versioned records, compiles proxy configuration, caches compiled output, reads namespace-scoped TLS records, and exposes an internal reconciliation surface. It needs a defensive source-audit and hardening pass before production use.

Review the source and fix trust-boundary weaknesses wherever authenticated identity, request metadata, persisted route state, secret references, compiled configuration, or cached results cross tenant or grammar boundaries. Diagnose the flaws from the source and observed local behavior. Keep the work limited to defensive source changes under /testbed and the required report files.

Required artifacts

After patching the source, write /app/output/findings.json as a non-empty JSON array. Each entry must include:

  • vulnerability_type: a bare CWE weakness identifier in the form CWE-<positive digits>
  • severity: LOW, MEDIUM, HIGH, or CRITICAL
  • affected_files: a list of modified paths under /testbed, either relative paths or absolute /testbed/... paths
  • root_cause: a concise explanation of the underlying flaw
  • description: the unsafe data flow and its security impact

Maintain /app/output/plan.md while you work. It must record the relevant subsystems, root causes, remediation approach, and the security and functional checks performed. The verifier scores the patched workspace and artifacts as submitted. Missing or malformed reports, broken builds, placeholders, and behavior regressions fail rather than being repaired or inferred.

Public API and tenant model

  • GET /health returns HTTP 200 while the service is healthy.
  • GET and POST /api/v1/routes list and admit route records.
  • GET /api/v1/routes/{name}/config returns compiled configuration.
  • The route list and configuration endpoints accept a namespace query parameter. A route POST accepts the same namespace JSON field. Omitting it uses the authenticated developer's assigned namespace.
  • The two development bearer tokens select team-a and team-b. Both may use the normal route workflows in their own namespace. The token values and non-sensitive development state are available through the configured local development environment.
  • Identical route and secret names may legitimately exist in different namespaces. A developer must never read, create, update, render, or receive a cached result for another namespace.
  • GET /api/v1/admin/secrets/{name}?namespace={namespace} remains available to the authenticated admin capability. Developer and anonymous callers remain denied.
  • The authenticated worker token can call GET /api/v1/internal/render-all, optionally scoped with namespace. No caller-controlled forwarding or origin metadata is an authentication credential.
  • Existing endpoint JSON field names and the route, items, config, and count response fields remain compatible. Additional cache, revision, or invalid-record metadata may remain present.

Behavior to preserve

  • A route contains name, host, path, service, optional namespace, optional path_type, optional tls_secret, and optional annotations.
  • path_type defaults to Prefix; Prefix and Exact are supported. DNS hosts and single-label wildcard hosts such as *.example.test are valid.
  • Safe rewrite, request-header, and rate-limit annotations remain supported. Other annotation families fail safely.
  • A rewrite-target is one absolute path-like configuration token: it begins with / and contains no whitespace, control characters, or directive delimiters that could add arguments or change grammar.
  • set-header-{Header-Name} derives a syntactically valid HTTP header name. Its value is a string of at most 512 bytes. Printable values containing ordinary punctuation, spaces, semicolons, quotes, backslashes, or dollar signs are valid data and must be compiled as one safely quoted configuration argument. Newlines and other control characters are invalid.
  • For compatibility, service.port and rate-limit-rps accept either JSON integers or base-10 ASCII digit strings. String forms contain only 0..9: signs, surrounding whitespace, exponent notation, separators, and non-ASCII digits are invalid. Both representations are validated, range checked (1..65535 and 1..10000), and canonicalized before persistence or render.
  • A valid TLS reference resolves only within the route's namespace. Compiled output uses server-controlled, namespace-qualified certificate and key file paths and never contains certificate, private-key, token, or other secret payload material.
  • Safe legacy records already in persisted state remain listable and renderable, including their compatible numeric representations and safe annotations.

Security and reconciliation properties

  • Authorization is evaluated against authenticated capabilities and tenant assignment before object lookup or cache access. Request bodies, query parameters, and forwarding headers do not expand the caller's tenant scope.
  • Request data and persisted controller state are separate untrusted inputs. Records loaded from disk must pass the same normalization and security invariants before they are listed, compiled, cached, or published, even if they did not pass through current admission code.
  • A malformed persisted record is rejected or skipped in isolation. It must not appear in normal route listings, reach compiled output, crash an endpoint, or prevent unrelated valid routes from being reconciled. The render-all response may report it through invalid_count.
  • Cache identity includes the tenant/object identity and is valid only for the current route revision and policy version. Authorization precedes cache hits; identically named routes cannot share output; and a state revision change cannot return stale compiled configuration.
  • Route names, hosts, paths, upstream definitions, TLS references, annotations, and persisted equivalents must not add directives, change directive arity, escape quoting, inject control characters, or otherwise alter proxy grammar.
  • Unknown, malformed, or unsafe request metadata receives an HTTP 4xx response rather than being persisted or causing an HTTP 500 response.

Environment and scope

  • Application source is writable under /testbed.
  • A non-sensitive development runtime is selected through APP_ENV_FILE for local probes. Verifier configuration, seed fixtures, and live state are protected and out of scope; the verifier resets live state between checks.
  • The verifier builds the submitted Go source and starts it on localhost:9090.
  • Tests, solution files, verifier-owned fixtures, scoring files, and runtime internals not explicitly listed above are out of scope.
  • Internet access is disabled. Do not add third-party dependencies, rotate credentials, move state files, or modify files outside /testbed except for /app/output/findings.json and /app/output/plan.md.

Working guidelines

  1. Fix root causes at the trust boundary rather than filtering one observed payload or hardcoding verifier values. Scoreable behavior is defined by the security properties, not a particular patch shape.
  2. Do not disable route admission, listing, rendering, valid legacy records, namespaced TLS references, admin access, worker reconciliation, or caching. Do not replace the service with canned responses.
  3. Keep /app/output/plan.md current and write concrete findings as they are established. Artifact presence alone does not earn credit.
  4. Work with concrete actions. If no specific file, test, patch, or artifact update remains, leave the best valid patch and reports and finish.
  5. Keep terminal output compact and relevant. Prefer targeted source ranges and concise build or probe results over full-file and full-log dumps.
  6. Use bounded waits only when a documented state transition requires one. Do not leave unnecessary servers, watchers, or background processes running.
  7. Validate changed security behavior and key legitimate workflows; avoid unrelated broad fuzzing once those checks are clear.