Skip to content

Commit db6d5c3

Browse files
author
dilanbhalla
committed
file/buffer write dataflow queries complete
1 parent 05a4798 commit db6d5c3

15 files changed

+131
-158
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-359/PrivateCleartextBufferWrite.qhelp

Lines changed: 0 additions & 5 deletions
This file was deleted.

cpp/ql/src/experimental/Security/CWE/CWE-359/PrivateCleartextBufferWrite.ql

Lines changed: 0 additions & 69 deletions
This file was deleted.

cpp/ql/src/experimental/Security/CWE/CWE-359/PrivateCleartextFileWrite.qhelp

Lines changed: 0 additions & 5 deletions
This file was deleted.

cpp/ql/src/experimental/Security/CWE/CWE-359/PrivateCleartextFileWrite.ql

Lines changed: 0 additions & 54 deletions
This file was deleted.

cpp/ql/src/experimental/Security/CWE/CWE-359/PrivateCleartextStorage.qhelp renamed to cpp/ql/src/experimental/Security/CWE/CWE-359/PrivateCleartextWrite.qhelp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"qhelp.dtd">
44
<qhelp>
55
<overview>
6-
<p>Private data that is stored unencrypted is accessible to an attacker who gains access to the
6+
<p>Private data that is stored in a file or buffer unencrypted is accessible to an attacker who gains access to the
77
storage.</p>
88

99
</overview>
1010
<recommendation>
1111

12-
<p>Ensure that private data is always encrypted before being stored, especially before writing to a file.
12+
<p>Ensure that private data is always encrypted before being stored.
1313
It may be wise to encrypt information before it is put into a buffer that may be readable in memory.</p>
1414

1515
<p>In general, decrypt private data only at the point where it is necessary for it to be used in
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Exposure of private information
3+
* @description If private information is written to an external location, it may be accessible by
4+
* unauthorized persons.
5+
* @kind path-problem
6+
* @problem.severity error
7+
* @precision high
8+
* @id cpp/exposure-of-sensitive-information
9+
* @tags security
10+
* external/cwe/cwe-359
11+
*/
12+
13+
14+
import cpp
15+
import experimental.semmle.code.cpp.security.PrivateCleartextWrite
16+
import experimental.semmle.code.cpp.security.PrivateCleartextWrite::PrivateCleartextWrite
17+
18+
from WriteConfig b, DataFlow::Node source, DataFlow::Node sink
19+
where b.hasFlow(source, sink)
20+
select sink, "This write may contain unencrypted data"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import cpp
2+
import semmle.code.cpp.security.BufferWrite
3+
import semmle.code.cpp.security.FileWrite
4+
5+
/**
6+
* A write, to either a file or a buffer
7+
*/
8+
abstract class ExternalLocationSink extends DataFlow::ExprNode { }
9+
10+
class Temp extends ExternalLocationSink {
11+
Temp() {
12+
none()
13+
}
14+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Provides a taint-tracking configuration for reasoning about private information flowing unencrypted to an external location.
3+
*/
4+
5+
import cpp
6+
import semmle.code.cpp.dataflow.TaintTracking
7+
import experimental.semmle.code.cpp.security.PrivateData
8+
import semmle.code.cpp.security.FileWrite
9+
import semmle.code.cpp.dataflow.TaintTracking
10+
import experimental.semmle.code.cpp.security.ExternalLocationSink
11+
12+
module PrivateCleartextWrite {
13+
/**
14+
* A data flow source for private information flowing unencrypted to an external location.
15+
*/
16+
abstract class Source extends DataFlow::ExprNode { }
17+
18+
/**
19+
* A data flow sink for private information flowing unencrypted to an external location.
20+
*/
21+
abstract class Sink extends DataFlow::ExprNode { }
22+
23+
/**
24+
* A sanitizer for private information flowing unencrypted to an external location.
25+
*/
26+
abstract class Sanitizer extends DataFlow::ExprNode { }
27+
28+
/** A call to any method whose name suggests that it encodes or encrypts the parameter. */
29+
class ProtectSanitizer extends Sanitizer {
30+
ProtectSanitizer() {
31+
exists(Function m, string s |
32+
this.getExpr().(FunctionCall).getTarget() = m and
33+
m.getName().regexpMatch("(?i).*" + s + ".*")
34+
|
35+
s = "protect" or s = "encode" or s = "encrypt"
36+
)
37+
}
38+
}
39+
40+
class WriteConfig extends TaintTracking::Configuration {
41+
WriteConfig() { this = "Write configuration" }
42+
43+
override predicate isSource(DataFlow::Node source) { source instanceof Source }
44+
45+
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
46+
47+
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
48+
}
49+
50+
class PrivateDataSource extends Source {
51+
PrivateDataSource() { this.getExpr() instanceof PrivateDataExpr }
52+
}
53+
54+
class WriteSink extends Sink {
55+
WriteSink() {
56+
exists(FileWrite f, BufferWrite b |
57+
this.asExpr() = f.getASource()
58+
or
59+
this.asExpr() = b.getAChild()
60+
)
61+
}
62+
}
63+
// class ExternalLocation extends Sink {
64+
// ExternalLocation() { this instanceof ExternalLocationSink }
65+
// }
66+
}

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-359/semmle/tests/PrivateCleartextBufferWrite.expected

Lines changed: 0 additions & 13 deletions
This file was deleted.

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-359/semmle/tests/PrivateCleartextBufferWrite.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)