Skip to content

Added MissingSecurityMetadata query #8437

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

Merged

Conversation

atorralba
Copy link
Contributor

@atorralba atorralba commented Mar 14, 2022

Adds a QL for QL query that raises a warning whenever a .ql file is tagged as @tag security but it doesn't have a @security-severity tag, or vice versa.

@atorralba atorralba requested a review from a team as a code owner March 14, 2022 16:16
@MathiasVP
Copy link
Contributor

Should we maybe exclude queries in the experimental directory?

@atorralba
Copy link
Contributor Author

Good point, thanks!

Also, can we prevent the .ql files used as "sources" from being considered test queries? I could always add a blank .expected file for them, but it seems a bit counter-intuitive.

@MathiasVP
Copy link
Contributor

Also, can we prevent the .ql files used as "sources" from being considered test queries? I could always add a blank .expected file for them, but it seems a bit counter-intuitive.

Hm, yes. That is an interesting issue 😂. I don't know if that's possible.

@atorralba atorralba force-pushed the atorralba/missing-security-severity-query branch from 40625b9 to 03f3535 Compare March 14, 2022 16:53
@erik-krogh
Copy link
Contributor

Maybe also exclude the examples directory. Most of the JS warnings are from that folder.

Also, can we prevent the .ql files used as "sources" from being considered test queries? I could always add a blank .expected file for them, but it seems a bit counter-intuitive.

Not currently possible.
Most of the time the PR checks work as the best test-case, as it's effectively a dist-upgrade on every PR.

@atorralba
Copy link
Contributor Author

Maybe also exclude the examples directory. Most of the JS warnings are from that folder.

Done, thanks!

Not currently possible.

👍 Just added the blank .expected files for these tests, but will keep in mind what you mentioned about just looking at the PR checks for future queries.

@erik-krogh
Copy link
Contributor

Just added the blank .expected files for these tests, but will keep in mind what you mentioned about just looking at the PR checks for future queries.

Yes, it's specifically the Code scanning results / CodeQL line that is interesting to look at.
You can see 38 results with the current version of the query, most of which looks like TPs 🙈


Currently you check that all queries that has a @tag security also has a @security-severity.
What if a query has a @security-severity but no @tag security? Should we also flag those?

@MathiasVP
Copy link
Contributor

MathiasVP commented Mar 15, 2022

Yes, it's specifically the Code scanning results / CodeQL line that is interesting to look at.
You can see 38 results with the current version of the query, most of which looks like TPs 🙈

There are many very old C++ queries that have no security severity because they're not part of any modern suite. To remove those results, it would be helpful to exclude queries that have no @precision tag.

It would also remove the FPs from results like ExternalAPIsUsedWithUntrustedData.

@atorralba
Copy link
Contributor Author

What if a query has a @security-severity but no @tag security? Should we also flag those?

I think that's less of a problem for us since AFAIK the requirement is "all security queries should have a security-severity score", not the other way around (which means a customer noticing this is less likely). But yes, it's indeed an inconsistency that could point out a mistake being made, so we could flag it too (although with a different QL for QL query? If not, the alert message may become confusing).

To remove those results, it would be helpful to exclude queries that have no @precision tag.

Makes sense! Done in 82b2fd2.

@erik-krogh
Copy link
Contributor

If not, the alert message may become confusing).

You could change the alert message depending on what is flagged.

from TopLevel t, string msg
where 
  missingSeverity(t) and msg = "This query file is missing a `@security-severity` tag."
  or
  missingSecurityTag(t) and msg = "This query file is missing a `@tag secrity`". 
select t, msg

@atorralba
Copy link
Contributor Author

You could change the alert message depending on what is flagged.

Yep, that's less complicated than what I initially imagined :-P

Done in fd4c9fd, I also renamed the query so that it adjusts better to what it's doing now.

@atorralba atorralba changed the title Added MissingSecuritySeverity query Added MissingSecurityMetadata query Mar 15, 2022
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

LGTM!

@atorralba atorralba merged commit 6d54142 into github:main Mar 15, 2022
@atorralba atorralba deleted the atorralba/missing-security-severity-query branch March 15, 2022 10:42
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.

3 participants