Skip to content

Allow URL-encoded newlines by replacing CR/LF with spaces in httplib #2033

Closed
@tim-janik

Description

@tim-janik

Description:
Currently, the cpp-httplib library rejects requests containing CR, LF, or NUL characters within field values, as per this commit:
975cf0d
Due to this issue:
#1908
Released with cpp-httplib v0.17.1.

This behavior is problematic for use cases where URLs include encoded newlines (e.g., %0A), for instance in the llama-server project (PR#11150) where a multi-line string in a URL is used to pre-fill the prompt text field (newlines are useful and needed in that context).

Steps to Reproduce:

  1. Send a request with a URL containing %0A (e.g., http://localhost:8080/?something=%0A).
  2. A cpp-httplib server returns a 400 error, indicating an invalid request.

Expected Behavior:
According to RFC 9110, servers should replace CR, LF, and NUL characters with spaces in field values or rejecting the request. In the above case, using spaces would be vastly preferable, instead of not allowing the server logic to handle requests at all.
For instance www.google.com/search?q=cpp-httplib%0A also continues to process HTTP requests in the face of %0A in a URL.

Current Behavior:
The library rejects any request containing CR, LF, or NUL in field values, resulting in a 400 error.

Proposed Solution:
Modify e.g. the parse_header() function in httplib.h to replace CR, LF, and NUL characters with spaces instead of rejecting the request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions