Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: encode x-error-msg as JSON - so it does not contain <CR> or <LF> #1782

Merged
merged 1 commit into from
Sep 4, 2023

Commits on Sep 4, 2023

  1. api: encode x-error-msg as JSON - so it does not contain <CR> or <LF>

    When the server raises an exception in a HTTP request handler context,
    more often than not, the exception is sent back to the client in the
    body.
    
    Additionally, the message of the exception (if any), is also copied as
    is in a x-error-msg HTTP header.
    
    That said, HTTP headers must obey strict rules. The "\r\n" sequence
    indicate the end of the current HTTP header. When using aiohttp, the
    library rejects any header that has a "\r" or "\n" in its value:
    
      ValueError: Newline or carriage return character detected in HTTP status message or header. This is a potential security issue.
    
    As an example, any curtin.util.ProcessExecutionError exception will
    contain "\n" characters when converted into a string.
    
    We now encode the error message as JSON before copying it in the HTTP
    header.
    
    Signed-off-by: Olivier Gayot <[email protected]>
    ogayot committed Sep 4, 2023
    Configuration menu
    Copy the full SHA
    b866bd2 View commit details
    Browse the repository at this point in the history