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

Conversation

ogayot
Copy link
Member

@ogayot ogayot commented Sep 1, 2023

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.

Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

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 ogayot merged commit 8e03050 into canonical:main Sep 4, 2023
10 checks passed
@ogayot ogayot deleted the fix-x-error-msg-cr-lf branch September 4, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants