Skip to content

Availability of raw body bytes when using parsers #691

@stevegraham

Description

@stevegraham

We're implementing HTTP signatures in our Elixir applications. We need to be able to hash the request body in order to verify the overall request signature. As Cowboy only allows the body to be read once and Plug does not keep the raw bytes from the socket anywhere doing this is impossible when using any of the Plug parsers.

Verifying the signature of incoming requests is a widespread pattern (Twilio, Stripe, etc) and IMO something any web library should not make it difficult to do.

I am proposing some solutions but want to begin a general discussion around design with the maintainers before writing code:

  • Plug.Conn.read_body/2 should store the raw body somewhere in there Conn's structure. If so where? Another field on the struct, or as private data? (This could allow read_body to be called multiple times idempotently during a request, hiding the leaky cowboy abstraction).

  • Plug.Conn.read_body/2 should allow the registration of callback functions that are called with the tuple return value of the function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions