Skip to content

Java: Update the alert messages to better follow the style guide #10528

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
merged 6 commits into from
Oct 3, 2022

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Sep 22, 2022

The tests are failing, and that's expected (there is an internal PR that updates the expected output).

I've been working on making the alert-messages consistent across languages, and some fan out work from that is ensuring that the alert-messages follow the style guide (which I've also revised).

Fixes done as part of this PR:

  • Don't repeat the alert-location as a link.
  • Avoid non-descriptive links to "here", or non-descriptive mentions of "here".
  • Add single-quotes are code snippets.
  • Add full stop at the end of alert-messages.
  • Try to get more alert-messages to be consistent with other languages.
  • Use "depends on" in taint-tracking queries, and "flows to" in dataflow-queries.

Some of the messages become inconsistent with other languages, but I'm updating one language at a time, so some will get out of sync.

Some other PRs in this series: JS, Py, Rb, Go, C, C# (draft).
Style guide update.


Side-note:
Copilot is great at writing consistent alert-messages. It reads the other tabs I have open.
Screenshot 2022-09-22 at 19 57 10

@erik-krogh erik-krogh added the WIP This is a work-in-progress, do not merge yet! label Sep 22, 2022
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 16 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 15 potential problems in the proposed changes. Check the Files changed tab for more details.

@erik-krogh erik-krogh added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Sep 22, 2022
@github-actions github-actions bot added Python and removed QL-for-QL labels Sep 22, 2022
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 15 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 15 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 15 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

@github-actions github-actions bot removed the Kotlin label Sep 26, 2022
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

@erik-krogh erik-krogh removed the WIP This is a work-in-progress, do not merge yet! label Sep 26, 2022
@erik-krogh erik-krogh marked this pull request as ready for review September 26, 2022 11:29
@erik-krogh erik-krogh requested a review from a team as a code owner September 26, 2022 11:29
Comment on lines 63 to 80
from EqualsMethod m
where
exists(m.getBody()) and
exists(Parameter p | p = m.getAParameter() |
// The parameter has no type test
not hasTypeTest(p) and
// If the parameter is passed to a method for which we don't have the source
// we assume it's ok
not exists(MethodAccess ma |
not exists(ma.getMethod().getBody()) and
ma.getAnArgument() = p.getAnAccess()
)
) and
not m.getDeclaringType() instanceof Interface and
// Exclude `equals` methods that implement reference-equality.
not m instanceof ReferenceEquals and
not m instanceof UnimplementedEquals
select m, "equals() method does not check argument type."
select m, "This 'equals()' method does not check argument type."

Check warning

Code scanning / CodeQL

Consistent alert message

The java/unchecked-cast-in-equals query does not have the same alert message as cs.
Comment on lines 20 to +22
from QueryInjectionSink query, DataFlow::PathNode source, DataFlow::PathNode sink
where queryTaintedBy(query, source, sink)
select query, source, sink, "This SQL query depends on $@.", source.getNode(),
"a user-provided value"
select query, source, sink, "This query depends on a $@.", source.getNode(), "user-provided value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/sql-injection query does not have the same alert message as cs, js, py, rb.
Comment on lines 18 to 21
from LogInjectionConfiguration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select source.getNode(), source, sink, "This user-provided value flows to a $@.", sink.getNode(),
"log entry"
select sink.getNode(), source, sink, "Log entry depends on a $@.", source.getNode(),
"user-provided value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/log-injection query does not have the same alert message as js, py.
Comment on lines 32 to 37
from
DataFlow::PathNode source, DataFlow::PathNode sink, StringFormat formatCall,
ExternallyControlledFormatStringConfig conf
where conf.hasFlowPath(source, sink) and sink.getNode().asExpr() = formatCall.getFormatArgument()
select formatCall.getFormatArgument(), source, sink,
"$@ flows to here and is used in a format string.", source.getNode(), "User-provided value"
select formatCall.getFormatArgument(), source, sink, "Format string depends on a $@.",
source.getNode(), "user-provided value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/tainted-format-string query does not have the same alert message as cpp, js.
Comment on lines 18 to +21
from DataFlow::PathNode source, DataFlow::PathNode sink, UnsafeDeserializationConfig conf
where conf.hasFlowPath(source, sink)
select sink.getNode().(UnsafeDeserializationSink).getMethodAccess(), source, sink,
"Unsafe deserialization of $@.", source.getNode(), "user input"
"Unsafe deserialization depends on a $@.", source.getNode(), "user-provided value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/unsafe-deserialization query does not have the same alert message as js, py.
Comment on lines 52 to +56
from DataFlow::PathNode source, DataFlow::PathNode sink, XxeConfig conf
where conf.hasFlowPath(source, sink)
select sink.getNode(), source, sink,
"A $@ is parsed as XML without guarding against external entity expansion.", source.getNode(),
"user-provided value"
"XML parsing depends on a $@ without guarding against external entity expansion.",
source.getNode(), "user-provided value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/xxe query does not have the same alert message as js, py.
Comment on lines 20 to +25
from DataFlow::PathNode source, DataFlow::PathNode sink, PolynomialBackTrackingTerm regexp
where hasPolynomialReDoSResult(source, sink, regexp)
select sink, source, sink,
"This $@ that depends on $@ may run slow on strings " + regexp.getPrefixMessage() +
"This $@ that depends on a $@ may run slow on strings " + regexp.getPrefixMessage() +
"with many repetitions of '" + regexp.getPumpString() + "'.", regexp, "regular expression",
source.getNode(), "a user-provided value"
source.getNode(), "user-provided value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/polynomial-redos query does not have the same alert message as py.
Comment on lines 22 to 32
from LocalVariableDeclExpr ve, LocalVariableDecl v
where
v = ve.getVariable() and
not assigned(v) and
not read(v) and
(not exists(ve.getInit()) or exprHasNoEffect(ve.getInit())) and
// Remove contexts where Java forces a variable declaration: enhanced-for and catch clauses.
// Rules about catch clauses belong in an exception handling query
not exceptionVariable(ve) and
not enhancedForVariable(ve)
select v,
"Unused local variable " + v.getName() +
". The variable is never read or written to and should be removed."
select v, "Variable " + v.getName() + " is not used."

Check warning

Code scanning / CodeQL

Consistent alert message

The java/unused-local-variable query does not have the same alert message as py.
Comment on lines 20 to 29
from
DataFlow::PathNode source, DataFlow::PathNode sink, MethodAccess m, Expr e,
ConditionalBypassFlowConfig conf
where
conditionControlsMethod(m, e) and
sink.getNode().asExpr() = e and
conf.hasFlowPath(source, sink)
select m, source, sink,
"Sensitive method may not be executed depending on $@, which flows from $@.", e, "this condition",
source.getNode(), "user input"
"Sensitive method may not be executed depending on a $@, which flows from $@.", e,
"this condition", source.getNode(), "user-controlled value"

Check warning

Code scanning / CodeQL

Consistent alert message

The java/user-controlled-bypass query does not have the same alert message as cs, js.
@erik-krogh erik-krogh merged commit 3d00a61 into github:main Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
depends on internal PR This PR should only be merged in sync with an internal Semmle PR documentation Java
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants