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

deny injection of custom http headers #4818

Closed
xppt opened this issue Jun 12, 2020 · 3 comments
Closed

deny injection of custom http headers #4818

xppt opened this issue Jun 12, 2020 · 3 comments

Comments

@xppt
Copy link

xppt commented Jun 12, 2020

Hello!

I've noticed, that aiohttp is simply concatenating server-response (or client-request) header like this, w/o any validation:

    line = status_line + '\r\n' + ''.join(
        [k + ': ' + v + '\r\n' for k, v in headers.items()])

Which may be not okay, if some of the header values were based on user input.

Consider this example:

import aiohttp.web
async def handler(req: aiohttp.web.Request):
    return aiohttp.web.Response(headers={
        'X-Debug-Param': req.query.get('param', ''),
    })
app = aiohttp.web.Application()
app.add_get('/', handler)

This code seems to be fine. Unfortunately it is not, since an attacker can craft urls that will force this handler to return any custom http-headers, or skip some of the existing ones, or broke http payload:

/?param=%0d%0aLocation:%20https://malware.host/  # open redirect
/?param=%0d%0aSet-Cookie:%20...                  # set some cookie
/?param=%0d%0aContent-Length:%2040%0d%0a         # skip next headers

and so on.

I think that aiohttp should raise an exception for any http-reason, header-name or header-value that contains \r or \n characters, instead of breaking http payload silently.

Actually this is what flask/werkzeug do for header-value:

	if u"\n" in value or u"\r" in value:
		raise ValueError(
			"Detected newline in header value.  This is "
			"a potential security problem"
		)
@asvetlov
Copy link
Member

Sounds good.
We need a champion for this issue!

@webknjaz
Copy link
Member

@xppt this sounds like a security issue. Posting such things on public forums is considered a bad tone security-wise: https://github.com/aio-libs/aiohttp/security/policy. Please consider practicing responsible disclosure next time.

@asvetlov
Copy link
Member

Not such bad I think.
I rather consider it a minor issue.
aiohttp is a library. If a code that uses the library doesn't check what is passed to aiohttp -- many very bad things are possible.
But I agree: If we can protect sending malformed HTTP header values -- let's do it.

connorbrinton added a commit to connorbrinton/gql that referenced this issue Dec 6, 2021
A new version of aiohttp has been released, with [an important fix preventing header injection](aio-libs/aiohttp#4818). I looked through the aiohttp changelog and wasn't able to find any breaking changes, so I believe it should be safe to use with gql.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants