Skip to content

Commit f944ff4

Browse files
committed
Create getAValueFormattedMessageComponent
1 parent 05a9480 commit f944ff4

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

go/ql/lib/semmle/go/Concepts.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,17 @@ module RegexpReplaceFunction {
355355
* extend `LoggerCall::Range` instead.
356356
*/
357357
class LoggerCall extends DataFlow::Node instanceof LoggerCall::Range {
358+
/** Gets a node that is a part of the logged message. */
359+
DataFlow::Node getAMessageComponent() { result = super.getAMessageComponent() }
360+
358361
/**
359-
* Gets a node whose value is a part of the logged message. Note that
360-
* components corresponding to the format specifier "%T" are excluded as
362+
* Gets a node whose value is a part of the logged message.
363+
*
364+
* Components corresponding to the format specifier "%T" are excluded as
361365
* their type is logged rather than their value.
362366
*/
363-
DataFlow::Node getAMessageComponent() {
364-
result = super.getAMessageComponent() and
367+
DataFlow::Node getAValueFormattedMessageComponent() {
368+
result = this.getAMessageComponent() and
365369
not exists(string formatSpecifier |
366370
formatSpecifier.regexpMatch("%[^%]*T") and
367371
result = this.(StringOps::Formatting::StringFormatCall).getOperand(_, formatSpecifier)

go/ql/lib/semmle/go/security/CleartextLoggingCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module CleartextLogging {
4040
* An argument to a logging mechanism.
4141
*/
4242
class LoggerSink extends Sink {
43-
LoggerSink() { this = any(LoggerCall log).getAMessageComponent() }
43+
LoggerSink() { this = any(LoggerCall log).getAValueFormattedMessageComponent() }
4444
}
4545

4646
/**

go/ql/lib/semmle/go/security/LogInjectionCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module LogInjection {
3535

3636
/** An argument to a logging mechanism. */
3737
class LoggerSink extends Sink {
38-
LoggerSink() { this = any(LoggerCall log).getAMessageComponent() }
38+
LoggerSink() { this = any(LoggerCall log).getAValueFormattedMessageComponent() }
3939
}
4040

4141
/**

go/ql/src/Security/CWE-352/ConstantOauth2State.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ predicate privateUrlFlowsToAuthCodeUrlCall(DataFlow::CallNode call) {
138138

139139
module FlowToPrintConfig implements DataFlow::ConfigSig {
140140
additional predicate isSinkCall(DataFlow::Node sink, DataFlow::CallNode call) {
141-
exists(LoggerCall logCall | call = logCall | sink = logCall.getAMessageComponent())
141+
exists(LoggerCall logCall | call = logCall |
142+
sink = logCall.getAValueFormattedMessageComponent()
143+
)
142144
}
143145

144146
predicate isSource(DataFlow::Node source) { source = any(AuthCodeUrl m).getACall().getResult() }

go/ql/test/library-tests/semmle/go/concepts/LoggerCall/LoggerCall.ql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ import ModelValidation
44
import utils.test.InlineExpectationsTest
55

66
module LoggerTest implements TestSig {
7-
string getARelevantTag() { result = "logger" }
7+
string getARelevantTag() { result = ["type-logger", "logger"] }
88

99
predicate hasActualResult(Location location, string element, string tag, string value) {
1010
exists(LoggerCall log |
1111
log.getLocation() = location and
1212
element = log.toString() and
13-
value = log.getAMessageComponent().toString() and
14-
tag = "logger"
13+
(
14+
value = log.getAValueFormattedMessageComponent().toString() and
15+
tag = "logger"
16+
or
17+
value = log.getAMessageComponent().toString() and
18+
not value = log.getAValueFormattedMessageComponent().toString() and
19+
tag = "type-logger"
20+
)
1521
)
1622
}
1723
}

0 commit comments

Comments
 (0)