Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Introduced protections against DoS via unterminated read operations #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pixeebot[bot]
Copy link

@pixeebot pixeebot bot commented Aug 22, 2023

This change hardens all BufferedReader#readLine() operations against attack.

There is no way to call readLine() safely since it is, by its nature, a read that must be terminated by the stream provider. A stream influenced by an attacker could keep providing bytes until the JVM runs out of memory.

Fixing it is straightforward using an API which limits the amount of expected characters to some sane limit. This is what our changes look like:

+ import io.github.pixee.security.BoundedLineReader;
  ...
  BufferedReader reader = getReader();
- String line = reader.readLine(); // unlimited read, can lead to DoS
+ String line = BoundedLineReader.readLine(reader, 5_000_000); // limited to 5MB
More reading

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

Powered by: pixeebot (codemod ID: pixee:java/limit-readline)

@pixeebot
Copy link
Author

pixeebot bot commented Aug 29, 2023

I'm confident in this change, but I'm not a maintainer of this project. Do you see any reason not to merge it?

If this change was not helpful, or you have suggestions for improvements, please let me know!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants