Skip to content

Generate a request ID when X-Request-ID is not supplied #70

Closed

Description

@danmoz

Description

The API Gateway v2 adapter currently derives requestContext.requestId from the incoming X-Request-ID header.

If no upstream component supplies the header, the resulting request ID is empty. Additionally, when Caddy is directly Internet-facing, the value may be entirely client-controlled.

caddy-lambda should ensure that every invocation has a useful correlation ID.

Proposed behaviour

When handling a request:

  1. Use an existing X-Request-ID where appropriate.
  2. If none exists, generate a request ID.
  3. Use the resulting value for:
    • requestContext.requestId
    • caddy-lambda structured logs
    • invocation logging
  4. Consider returning the ID to the client as X-Request-ID.

A UUID or similarly collision-resistant identifier would be sufficient.

We should decide separately whether incoming client-supplied IDs should always be trusted or whether caddy-lambda should distinguish between an external request ID and its own internal correlation ID.

Acceptance criteria

  • Every Lambda invocation has a non-empty request ID.
  • The same ID is available in the Lambda event and caddy-lambda logs.
  • Requests without X-Request-ID receive a generated ID.
  • Behaviour for an existing X-Request-ID is documented and tested.

Activity

  1. danmoz commented on Sep 5, 2026

    @danmoz
    OwnerAuthor

    Adding the security label. /oc please create a PR for this one. The request ID should be as close to the real API GW ID as possible, in case the lambda app is validating the value.

  2. opencode-agent commented on Sep 5, 2026

    @opencode-agent
    Contributor

    Created PR #72

    New%20session%20-%202026-09-05T19%3A26%3A02.850Z
    opencode session  |  github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions