Sitelet https://web.archive.org/web/20251211134646/https://github.com/github/codeql/pull/11574
Skip to content

Conversation

@henrymercer
Copy link
Contributor

@henrymercer henrymercer commented Dec 5, 2022 •

We distinguish queries in Code scanning by their ID, so it's important that each query has a unique ID. This PR adds a PR check to ensure that query IDs are unique, and fixes up duplicate query IDs for Java and Python.

For now, we limit our scope to just the duplicate IDs in src directories, which correspond to query packs. In the future, we may want to extend this to eliminate duplicate IDs in test packs too, but the changes involved there are more widespread, so let's break that out into a separate PR.

@henrymercer henrymercer force-pushed the henrymercer/check-query-ids branch from da1cdde to 9f10956 Compare December 5, 2022 19:04
@henrymercer henrymercer force-pushed the henrymercer/check-query-ids branch from 9f10956 to 2627632 Compare December 5, 2022 19:06
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022 •

QHelp previews:

java/ql/src/experimental/Security/CWE/CWE-400/LocalThreadResourceAbuse.qhelp

Uncontrolled thread resource consumption from local input source

The Thread.sleep method is used to pause the execution of current thread for specified time. When the sleep time is user-controlled, 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.

Recommendation

To guard against this attack, consider specifying an upper range of allowed sleep time or adopting the producer/consumer design pattern with Object.wait method to avoid performance problems or even resource exhaustion. For more information, refer to the concurrency tutorial of Oracle listed below or java/ql/src/Likely Bugs/Concurrency queries of CodeQL.

Example

The following example shows a bad situation and a good situation respectively. In the bad situation, a thread sleep time comes directly from user input. In the good situation, an upper range check on the maximum sleep time allowed is enforced.

class SleepTest {
	public void test(int userSuppliedWaitTime) throws Exception {
		// BAD: no boundary check on wait time
		Thread.sleep(userSuppliedWaitTime);

		// GOOD: enforce an upper limit on wait time
		if (userSuppliedWaitTime > 0 && userSuppliedWaitTime < 5000) {
			Thread.sleep(userSuppliedWaitTime);
		}
	}
}

References

@henrymercer
Copy link
Contributor Author

@github/codeql-python The QHelp changes are failing for TarSlipImprov.ql with the following:

./python/ql/src/experimental/Security/CWE-022bis/TarSlipImprov.qhelp: Could not find sample examples/TarSlip_1.py
./python/ql/src/experimental/Security/CWE-022bis/TarSlipImprov.qhelp: Could not find sample examples/NoHIT_TarSlip_1.py

This seems genuine since the examples don't exist. Do we have some other examples we can use here?

@henrymercer
Copy link
Contributor Author

@tausbn I've renamed the Qhelp file as you suggested

@github github deleted a comment from github-actions bot Dec 8, 2022
@henrymercer henrymercer marked this pull request as ready for review December 8, 2022 13:07
@henrymercer henrymercer requested review from a team as code owners December 8, 2022 13:07
Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

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

Python looks reasonable to me. 👍

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

Java 👍

@henrymercer
Copy link
Contributor Author

Thanks both!

@henrymercer henrymercer merged commit d196704 into main Dec 8, 2022
@henrymercer henrymercer deleted the henrymercer/check-query-ids branch December 8, 2022 15:31
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.

4 participants