Skip to content

Commit fa52514

Browse files
Add system.web tests for httponly cookie
1 parent 4467faa commit fa52514

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| Program.cs:16:22:16:59 | object creation of type HttpCookie | Cookie attribute 'HttpOnly' is not set to true. |
2+
| Program.cs:32:22:32:59 | object creation of type HttpCookie | Cookie attribute 'HttpOnly' is not set to true. |
3+
| Program.cs:38:22:38:80 | object creation of type HttpCookie | Cookie attribute 'HttpOnly' is not set to true. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Security Features/CWE-1004/CookieWithoutHttpOnly.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
class Program
2+
{
3+
void CookieDirectTrue()
4+
{
5+
var cookie = new System.Web.HttpCookie("sessionID");
6+
cookie.HttpOnly = true; // GOOD
7+
}
8+
9+
void CookieDirectTrueInitializer()
10+
{
11+
var cookie = new System.Web.HttpCookie("sessionID") { HttpOnly = true }; // GOOD
12+
}
13+
14+
void CookieDefault()
15+
{
16+
var cookie = new System.Web.HttpCookie("sessionID"); // $Alert // BAD: httpOnlyCookies is set to false by default
17+
}
18+
19+
void CookieDefaultForgery()
20+
{
21+
var cookie = new System.Web.HttpCookie("anticsrftoken"); // GOOD: not an auth cookie
22+
}
23+
24+
void CookieForgeryDirectFalse()
25+
{
26+
var cookie = new System.Web.HttpCookie("antiforgerytoken");
27+
cookie.HttpOnly = false; // GOOD: not an auth cookie
28+
}
29+
30+
void CookieDirectFalse()
31+
{
32+
var cookie = new System.Web.HttpCookie("sessionID"); // $Alert
33+
cookie.HttpOnly = false; // BAD
34+
}
35+
36+
void CookieDirectFalseInitializer()
37+
{
38+
var cookie = new System.Web.HttpCookie("sessionID") { HttpOnly = false }; // $Alert // BAD
39+
}
40+
41+
void CookieIntermediateTrue()
42+
{
43+
var cookie = new System.Web.HttpCookie("sessionID");
44+
bool v = true;
45+
cookie.HttpOnly = v; // GOOD: should track local data flow
46+
}
47+
48+
void CookieIntermediateTrueInitializer()
49+
{
50+
bool v = true;
51+
var cookie = new System.Web.HttpCookie("sessionID") { HttpOnly = v }; // GOOD: should track local data flow
52+
}
53+
54+
void CookieIntermediateFalse()
55+
{
56+
var cookie = new System.Web.HttpCookie("sessionID"); // MISSING:Alert
57+
bool v = false;
58+
cookie.HttpOnly = v; // BAD
59+
}
60+
61+
void CookieIntermediateFalseInitializer()
62+
{
63+
bool v = false;
64+
var cookie = new System.Web.HttpCookie("sessionID") { HttpOnly = v }; // $MISSING:Alert // BAD
65+
}
66+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.web>
4+
<httpCookies />
5+
</system.web>
6+
</configuration>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
3+
semmle-extractor-options: ${testdir}/../../../../../resources/stubs/System.Web.cs

0 commit comments

Comments
 (0)