Skip to content

Weak Hashing findings vanished from 1.1.11 ruleset? #18518

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

Closed
davewichers opened this issue Jan 16, 2025 · 17 comments
Closed

Weak Hashing findings vanished from 1.1.11 ruleset? #18518

davewichers opened this issue Jan 16, 2025 · 17 comments
Labels
awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. question Further information is requested Stale

Comments

@davewichers
Copy link

I maintain the OWASP Benchmark project:

Which is a test suite for testing the effectiveness of software security analysis tools. I've had codeQL scripts for scanning OWASP Benchmark for a while.

They can be found in the scripts folder here: https://github.com/OWASP-Benchmark/BenchmarkJava/tree/master/scripts

  • translateCodeQL.sh
  • runCodeQL.sh

You have to follow the codeQL install instructions listed in the translateCodeQL.sh script, then run translateCodeQL.sh and then runCodeQL.sh.

After completing, it puts the codeQL SARIF results file into the results/ folder and you can then score the tool against Benchmark by running createScoreards.sh.

I noticed that when using the latest version of CodeQL 2.20.1, with the 1.1.9 ruleset, it properly detected 69% of the Weak Hashing test cases in Benchmark (and had zero false positives). But when I upgraded to ruleset 1.1.11, it now detects none of them.

Is this on purpose? Or was a bug introduced. or mistake made, to cause those rules to go away in 1.1.11?

@davewichers davewichers added the question Further information is requested label Jan 16, 2025
@redsun82
Copy link
Contributor

Hey @davewichers, thanks a lot for reaching out with this! I'll circle this back to our internal team responsible for Java analysis 👍

@redsun82
Copy link
Contributor

Hey @davewichers, as reported in this change note, we recently removed reporting of MD5 and SHA1 hashing from the java/weak-cryptographic-algorithm to the less precise java/potentially-weak-cryptographic-algorithm, as the former was alerting on too many cases of legitimate non cryptographic usages of those hashes. Maybe you can switch to using that query instead in your benchmarking?

@davewichers
Copy link
Author

@redsun82 - the codeQL documentation related to finding out which rulepacks exist and how to use them is super confusing. Where is the list of ALL the published codeql rulepacks? I only found: codeql\java-queries and codeql\java-all, but when I try to use java-all, it says 'this is a library and does not contain queries to run'. I want to use ALL the codeQL java rules in my run. How do I do that?

@redsun82
Copy link
Contributor

Hi @davewichers, the concept of a set of queries is captured by "query suites":

I heard back from the team, and they advise to use the java-security-extended suite for the benchmark. To do so, you should provide java-security-extended or java-security-extended.qls as second positional argument to codeql database analyze. If you download the latest release for the full codeql bundle, that will be included together with precompiled queries which will make the command run faster. You can however also run the queries from a checkout of codeql, provided you give the right --search-path.

Where is the list of ALL the published codeql rulepacks?

Probably the best way to get that list is to run

codeql resolve queries

This will list all query suites with their .qls extension. The query suite argument to codeql database analyze can be provided either with or without that extension.

I'm sorry if you found the documentation lacking, we will try to make it better! 🙌

@davewichers
Copy link
Author

davewichers commented Jan 22, 2025 via email

@redsun82
Copy link
Contributor

redsun82 commented Feb 4, 2025

Hi @davewichers

I'm very sorry for answering so late to this, and that you encountered these problems!

I think the source of confusion here is that java-security-extended is not a query pack, but rather a subset thereof (which we call query suites). They are included in the codeql/java-all pack you already download, and then they can be run by providing them as is to codeql database analyze, i.e. without the codeql/ prefix. See my comment above:

To do so, you should provide java-security-extended or java-security-extended.qls as second positional argument to codeql database analyze

So in your case the correct analyze command should be

codeql database analyze owasp-benchmark java-security-extended --format=sarifv2.1.0 --output=results/Benchmark-v1.2_CodeQL.sarif

Before running that you can double check the query suite is included by running

codeql resolve queries

This should contain the lines

  java-code-scanning.qls - Standard Code Scanning queries for Java
  java-lgtm-full.qls - Standard LGTM queries for Java, including ones not displayed by default
  java-lgtm.qls - Standard LGTM queries for Java
  java-security-and-quality.qls - Security-and-quality queries for Java
  java-security-experimental.qls - Extended and experimental security queries for Java and Kotlin
  java-security-extended.qls - Security-extended queries for Java

Those are all possible positional arguments to codeql database analyze, with the .qls extension being optional, no further prefixes required.

I will try out a PR to clarify the documentation to the <packs,queries> argument to database analyze.

@redsun82 redsun82 added the awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. label Feb 5, 2025
@davewichers
Copy link
Author

davewichers commented Feb 19, 2025 via email

@davewichers
Copy link
Author

davewichers commented Feb 19, 2025 via email

Copy link
Contributor

github-actions bot commented Mar 6, 2025

This issue is stale because it has been open 14 days with no activity. Comment or remove the Stale label in order to avoid having this issue closed in 7 days.

@github-actions github-actions bot added the Stale label Mar 6, 2025
@davewichers
Copy link
Author

I'm still waiting for an answer to my last comment from @redsun82. Can you answer my question/help me to get this to actually work?

@github-actions github-actions bot removed the Stale label Mar 13, 2025
@rvermeulen
Copy link
Contributor

Hi @davewichers,

Sorry for the late response and confusion around using the security-extended query suite.

All our queries live in a query pack. For Java that pack is codeql/java-queries.
The codeql/java-all pack is the library pack the queries rely on and you shouldn't be concerned with that one.

To run a suite you can directly reference the query pack and the suite therein.

codeql database analyze \
<path-to-db> \
codeql/java-queries:codeql-suites/java-security-extended.qls \
--format=sarifv2.1.0 \
--output=results.sarif \
-j0 \
--download

Note this adds to additional flags -j0 to use all available threads and --download to download any missing query packs automatically (i.e., you can skip the codeql pack download step).

To resolve the queries in a suite you can use the codeql resolve queries command like:

codeql resolve queries codeql/java-queries:java-security-extended

Note that this doesn't support a --download flag so if you run the before the packs has been downloaded (with for example the above analyze command) you need to run codeql pack download codeql/java-queries beforehand.

If you want to resolve all the queries in a pack you can use the command:

codeql resolve queries codeql/java-queries:.

Not that this will also contain internal queries we use for telemetry and diagnostics, so it is advised to use the query suites to select the useful queries to run.

Let me know if this resolves your issue.

@davewichers
Copy link
Author

davewichers commented Mar 21, 2025

@rvermeulen - it appears this worked. Thanks for the detailed instructions. It would be nice if your documentation described how to do all this properly so users wouldn't have to open issues to figure out how to get this to work.

@rvermeulen
Copy link
Contributor

@davewichers

Good to hear it worked and thanks for the feedback. We have this documented at https://docs.github.com/en/code-security/codeql-cli/getting-started-with-the-codeql-cli/analyzing-your-code-with-codeql-queries#running-query-suites, but it sounds like we need to work on the discoverability of our documentation.

@davewichers
Copy link
Author

Yes. I couldn't find these details when I followed the normal path to the instructions on how to run queries. So, something should be improved to make these details/scenarios much easier to find.

@rvermeulen
Copy link
Contributor

Hi @davewichers,

Could you share your starting point in the docs so I can provide this as feedback to our docs team?

Copy link
Contributor

github-actions bot commented Apr 8, 2025

This issue is stale because it has been open 14 days with no activity. Comment or remove the Stale label in order to avoid having this issue closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 8, 2025
Copy link
Contributor

This issue was closed because it has been inactive for 7 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants