Skip to content

Commit e0dca2b

Browse files
authored
Merge pull request github#5185 from MathiasVP/block-integral-types-in-cgixss-query
C++: Add isBarrier to cpp/cgi-xss
2 parents eee49cd + 25beadc commit e0dca2b

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

cpp/ql/src/Security/CWE/CWE-079/CgiXss.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class Configuration extends TaintTrackingConfiguration {
3434
override predicate isSink(Element tainted) {
3535
exists(PrintStdoutCall call | call.getAnArgument() = tainted)
3636
}
37+
38+
override predicate isBarrier(Expr e) {
39+
super.isBarrier(e) or e.getUnspecifiedType() instanceof IntegralType
40+
}
3741
}
3842

3943
from QueryString query, Element printedArg, PathNode sourceNode, PathNode sinkNode

cpp/ql/test/query-tests/Security/CWE/CWE-079/semmle/CgiXss/CgiXss.expected

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ edges
88
| search.c:22:24:22:28 | *query | search.c:23:39:23:43 | query |
99
| search.c:22:24:22:28 | query | search.c:23:39:23:43 | query |
1010
| search.c:22:24:22:28 | query | search.c:23:39:23:43 | query |
11-
| search.c:41:21:41:26 | call to getenv | search.c:14:24:14:28 | *query |
12-
| search.c:41:21:41:26 | call to getenv | search.c:14:24:14:28 | *query |
13-
| search.c:41:21:41:26 | call to getenv | search.c:14:24:14:28 | query |
14-
| search.c:41:21:41:26 | call to getenv | search.c:14:24:14:28 | query |
15-
| search.c:41:21:41:26 | call to getenv | search.c:22:24:22:28 | *query |
16-
| search.c:41:21:41:26 | call to getenv | search.c:22:24:22:28 | *query |
17-
| search.c:41:21:41:26 | call to getenv | search.c:22:24:22:28 | query |
18-
| search.c:41:21:41:26 | call to getenv | search.c:22:24:22:28 | query |
11+
| search.c:51:21:51:26 | call to getenv | search.c:14:24:14:28 | *query |
12+
| search.c:51:21:51:26 | call to getenv | search.c:14:24:14:28 | *query |
13+
| search.c:51:21:51:26 | call to getenv | search.c:14:24:14:28 | query |
14+
| search.c:51:21:51:26 | call to getenv | search.c:14:24:14:28 | query |
15+
| search.c:51:21:51:26 | call to getenv | search.c:22:24:22:28 | *query |
16+
| search.c:51:21:51:26 | call to getenv | search.c:22:24:22:28 | *query |
17+
| search.c:51:21:51:26 | call to getenv | search.c:22:24:22:28 | query |
18+
| search.c:51:21:51:26 | call to getenv | search.c:22:24:22:28 | query |
1919
nodes
2020
| search.c:14:24:14:28 | *query | semmle.label | *query |
2121
| search.c:14:24:14:28 | query | semmle.label | query |
@@ -29,12 +29,12 @@ nodes
2929
| search.c:23:39:23:43 | query | semmle.label | query |
3030
| search.c:23:39:23:43 | query | semmle.label | query |
3131
| search.c:23:39:23:43 | query | semmle.label | query |
32-
| search.c:41:21:41:26 | call to getenv | semmle.label | call to getenv |
33-
| search.c:41:21:41:26 | call to getenv | semmle.label | call to getenv |
34-
| search.c:45:5:45:15 | Argument 0 | semmle.label | Argument 0 |
35-
| search.c:45:17:45:25 | Argument 0 indirection | semmle.label | Argument 0 indirection |
36-
| search.c:47:5:47:15 | Argument 0 | semmle.label | Argument 0 |
37-
| search.c:47:17:47:25 | Argument 0 indirection | semmle.label | Argument 0 indirection |
32+
| search.c:51:21:51:26 | call to getenv | semmle.label | call to getenv |
33+
| search.c:51:21:51:26 | call to getenv | semmle.label | call to getenv |
34+
| search.c:55:5:55:15 | Argument 0 | semmle.label | Argument 0 |
35+
| search.c:55:17:55:25 | Argument 0 indirection | semmle.label | Argument 0 indirection |
36+
| search.c:57:5:57:15 | Argument 0 | semmle.label | Argument 0 |
37+
| search.c:57:17:57:25 | Argument 0 indirection | semmle.label | Argument 0 indirection |
3838
#select
39-
| search.c:17:8:17:12 | query | search.c:41:21:41:26 | call to getenv | search.c:17:8:17:12 | query | Cross-site scripting vulnerability due to $@. | search.c:41:21:41:26 | call to getenv | this query data |
40-
| search.c:23:39:23:43 | query | search.c:41:21:41:26 | call to getenv | search.c:23:39:23:43 | query | Cross-site scripting vulnerability due to $@. | search.c:41:21:41:26 | call to getenv | this query data |
39+
| search.c:17:8:17:12 | query | search.c:51:21:51:26 | call to getenv | search.c:17:8:17:12 | query | Cross-site scripting vulnerability due to $@. | search.c:51:21:51:26 | call to getenv | this query data |
40+
| search.c:23:39:23:43 | query | search.c:51:21:51:26 | call to getenv | search.c:23:39:23:43 | query | Cross-site scripting vulnerability due to $@. | search.c:51:21:51:26 | call to getenv | this query data |

cpp/ql/test/query-tests/Security/CWE/CWE-079/semmle/CgiXss/search.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void bad_server2(char* query) {
2626
puts(do_search(query));
2727
}
2828

29-
void good_server(char* query) {
29+
void good_server1(char* query) {
3030
puts("<p>Query results for ");
3131
// GOOD: Escape HTML characters before adding to a page
3232
char* query_escaped = escape_html(query);
@@ -37,14 +37,25 @@ void good_server(char* query) {
3737
puts(do_search(query));
3838
}
3939

40+
int sscanf(const char *s, const char *format, ...);
41+
42+
void good_server2(char* query) {
43+
puts("<p>Query results for ");
44+
// GOOD: Only an integer is added to the page.
45+
int i = 0;
46+
sscanf(query, "value=%i", &i);
47+
printf("\n<p>%i</p>\n", i);
48+
}
49+
4050
int main(int argc, char** argv) {
4151
char* raw_query = getenv("QUERY_STRING");
42-
if (strcmp("good", argv[0]) == 0) {
43-
good_server(raw_query);
52+
if (strcmp("good1", argv[0]) == 0) {
53+
good_server1(raw_query);
4454
} else if (strcmp("bad1", argv[0]) == 0) {
4555
bad_server1(raw_query);
46-
} else {
56+
} else if (strcmp("bad2", argv[0]) == 0) {
4757
bad_server2(raw_query);
58+
} else if (strcmp("good2", argv[0]) == 0) {
59+
good_server2(raw_query);
4860
}
4961
}
50-

0 commit comments

Comments
 (0)