Skip to content

bpo-43813: Fixing DOS on http.server by limiting the characters getting logged. #26223

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DEMON1A
Copy link

@DEMON1A DEMON1A commented May 18, 2021

Due to the large characters limit on the first line of the request, Remote users was able to submit a huge method name and endpoint on the request that they can keep sending until python uses a large amount of memory until it freezes that could be achieved on a strong machine with almost 1000 requests.

The logging part was the most part that's using memory during the attack. so I think limiting the data getting passed into the output functions: log_request and log_message that uses: sys.stderr.write will be more fine to keep http.server handling the requests without stop.

The fix limits the request method characters getting logged into 10 characters only. if the request method is 60k A characters for example. it will just print out: AAAAAAAAAA... that doesn't consume memory.

Before the fix the memory usage kept increasing. after it the memory usage doesn't pass 6.0% using 5k requests.

https://bugs.python.org/issue43813

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@DEMON1A

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@jaswdr
Copy link

jaswdr commented May 20, 2021

@DEMON1A can you add some tests to it?

@DEMON1A
Copy link
Author

DEMON1A commented May 23, 2021

Hey @jaswdr, i'm kinda new to this stuff, what do you mean with tests like test cases vulnerable to this? and where should i add it?

@jaswdr
Copy link

jaswdr commented May 23, 2021

@DEMON1A you need to add tests for your changes

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jun 23, 2021
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants