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

Java: CWE-400 - Query to detect uncontrolled thread resource consumption #6717

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

Conversation

@luchua-bc
Copy link
Contributor

@luchua-bc luchua-bc commented Sep 20, 2021

Thread.sleep method is used to pause the execution of current thread for specified time. When it is used to keep several relevant tasks in synchronization and the sleep time is user-controlled data, especially in the web application context, it can be abused to cause all of a server's threads to sleep, leading to denial of service.

The query detects uncontrolled thread resource consumption in Java EE web applications, which checks:

  • sources of servlets and JSF
  • remote user input and local container configuration
  • both the javax and jakarta packages

Please consider to merge the PR. Thanks.

@luchua-bc luchua-bc force-pushed the java/thread-resource-abuse branch from 80bb663 to 2dc38ae Sep 23, 2021
@luchua-bc
Copy link
Contributor Author

@luchua-bc luchua-bc commented Sep 23, 2021

Thanks @Marcono1234 and @intrigus-lgtm for reviewing this PR. I've made requested changes.

Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Thanks for considering the review comments!
I have had a closer look at the implementation of this query now; hopefully these comments are useful as well.

Though as usual, feel free to consider them only as suggestions because I am not a member of this project.

@luchua-bc
Copy link
Contributor Author

@luchua-bc luchua-bc commented Sep 24, 2021

I've also added a new test case to detect remote source from an HTTP request header such as Retry-After:

protected void doHead2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get thread pause time from request header
String header = request.getHeader("Retry-After");
int retryAfter = Integer.parseInt(header);

@github github deleted a comment Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants