Skip to content

API: JSON errors for malformed bodies and unknown routes, bounded /api/activity paging, basic security headers #3617

Closed

Description

@integry

Problem

  1. A malformed JSON body on any path, without credentials, returns an HTML error page: curl -X POST <api>/api/tasks/revert -H "Content-Type: application/json" -d '{"a":' → 400 text/html <pre>SyntaxError: Unexpected end of JSON input … at parse (/usr/src/app/node_modules/body-parser/lib/types/json.js:93:21). With NODE_ENV=production the stack is omitted but the response is still HTML. Same for Content-Encoding: gzip with garbage (Error: incorrect header check … node:zlib), an unsupported charset (415 HTML) and a body over the limit (413). express.json() is mounted in packages/api/server.ts with no error handler.
  2. Unknown paths under /api/ return Express's HTML page (Cannot GET /api/config) instead of JSON.
  3. GET /api/activity?offset=99999999999999999999 (or the same value as limit) returns 500; ?limit=-1 or ?limit=1000000000 returns the whole log (about 237 KB instead of 13 KB); limit=abc is silently ignored (packages/api/routes/queueRoutes.ts, parseInt(...) || 50 passed to Redis lRange).
  4. GET /api/github/repos/..%2f..%2fetc%2fpasswd/propr/branches and /workflows return 500 "Failed to fetch branches from GitHub" instead of 400/404.
  5. GET /api/agent-definitions/templates returns 404 "Automation definition not found" (the alias treats templates as an id) while GET /api/automation-definitions/templates works; every other route of the alias works.
  6. Every response carries X-Powered-By: Express; there is no X-Content-Type-Options: nosniff; Access-Control-Allow-Credentials: true is sent even when the request has no Origin; 401 responses have no WWW-Authenticate.
  7. GET /api/task/{id}/history, /file-changes and /live-details return 200 with empty data for a task id that does not exist (the UI and CLI then show a nonexistent task as pending); docker-logs returns 404.

Expected / acceptance criteria

  • 1, 2: every error produced by the API process under /api/, /health and /mcp is JSON { "error": …, "code": … } with the right status (400 invalid JSON, 413 too large, 415 unsupported media type, 404 unknown route) and contains no stack trace or file path in any NODE_ENV.
  • 3: limit and offset are validated integers (limit 1–200, offset ≥ 0); invalid values are 400.
  • 4: owner/repo path segments are validated; invalid ones are 400.
  • 5: the alias serves templates like the canonical route.
  • 6: x-powered-by disabled; X-Content-Type-Options: nosniff on API responses; Access-Control-Allow-Credentials only on responses to an allowed Origin; WWW-Authenticate: Bearer on 401.
  • 7: the three task routes return 404 for an unknown task id.
  • Tests for each point; the OpenAPI spec is regenerated if response codes change.

Implementation

packages/api/server.ts (body-parser error middleware placed after the parsers, a JSON 404 for unmatched /api routes, app.disable('x-powered-by')), packages/api/routes/queueRoutes.ts, the GitHub proxy routes, the automation definition alias registration, the task detail routes. Check that the web UI and CLI handle the new 404 on task routes (see the related CLI and navigation issues in the other 0.9.2 release-fix plans; do not duplicate their work).

Notes

Do not change CORS origin rules. Do not add a dependency for headers; set them directly.

Activity

  1. propr-dev commented on Nov 17, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3617/claude-opus-5-5-api-json-errors-for-malfo-20261117-0149-myt
    • Base Branch: 3616-epic-0-9-d8b
    • Worktree: issue-3617-20261117-0149-claude-opus-5-5-myt

    🔍 Track Task Execution

  2. added a commit that references this issue on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions