Skip to content

Commit b1ab77f

Browse files
committed
C#: Add a copy of all experimental query tests (as is).
1 parent 13b2a0c commit b1ab77f

File tree

125 files changed

+1931
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1931
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Program.cs:13:33:13:37 | false | Cookie attribute 'HttpOnly' is not set to true. |
2+
| Program.cs:20:39:20:43 | false | Cookie attribute 'HttpOnly' is not set to true. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security Features/CWE-1004/CookieWithoutHttpOnly.ql
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.AspNetCore.Http;
5+
using Microsoft.AspNetCore.Authentication;
6+
7+
public class Startup
8+
{
9+
public void ConfigureServices(IServiceCollection services)
10+
{
11+
services.AddAuthentication().AddCookie(o =>
12+
{
13+
o.Cookie.HttpOnly = false;
14+
o.Cookie.SecurePolicy = Microsoft.AspNetCore.Http.CookieSecurePolicy.None;
15+
});
16+
17+
services.AddSession(options =>
18+
{
19+
options.Cookie.SecurePolicy = Microsoft.AspNetCore.Http.CookieSecurePolicy.None;
20+
options.Cookie.HttpOnly = false;
21+
});
22+
}
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Program.cs:25:34:25:38 | false | Cookie attribute 'HttpOnly' is not set to true. |
2+
| Program.cs:38:88:38:92 | false | Cookie attribute 'HttpOnly' is not set to true. |
3+
| Program.cs:61:34:61:34 | access to local variable v | Cookie attribute 'HttpOnly' is not set to true. |
4+
| Program.cs:68:88:68:88 | access to local variable v | Cookie attribute 'HttpOnly' is not set to true. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security Features/CWE-1004/CookieWithoutHttpOnly.ql
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
public class MyController : Microsoft.AspNetCore.Mvc.Controller
2+
{
3+
public void CookieDelete()
4+
{
5+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
6+
Response.Cookies.Delete("auth", cookieOptions); // GOOD: Delete call
7+
}
8+
9+
void CookieDirectTrue()
10+
{
11+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
12+
cookieOptions.HttpOnly = true;
13+
Response.Cookies.Append("auth", "secret", cookieOptions); // GOOD
14+
}
15+
16+
void CookieDirectTrueInitializer()
17+
{
18+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = true };
19+
Response.Cookies.Append("auth", "secret", cookieOptions); // GOOD
20+
}
21+
22+
void CookieDirectFalse()
23+
{
24+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
25+
cookieOptions.HttpOnly = false;
26+
Response.Cookies.Append("auth", "secret", cookieOptions); // BAD
27+
}
28+
29+
void CookieDirectFalseForgery()
30+
{
31+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
32+
cookieOptions.HttpOnly = false;
33+
Response.Cookies.Append("antiforgerytoken", "secret", cookieOptions); // GOOD: not an auth cookie
34+
}
35+
36+
void CookieDirectFalseInitializer()
37+
{
38+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = false };
39+
Response.Cookies.Append("auth", "secret", cookieOptions); // BAD
40+
}
41+
42+
void CookieIntermediateTrue()
43+
{
44+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
45+
bool v = true;
46+
cookieOptions.HttpOnly = v;
47+
Response.Cookies.Append("auth", "secret", cookieOptions); // GOOD: should track local data flow
48+
}
49+
50+
void CookieIntermediateTrueInitializer()
51+
{
52+
bool v = true;
53+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = v };
54+
Response.Cookies.Append("auth", "secret", cookieOptions); // GOOD: should track local data flow
55+
}
56+
57+
void CookieIntermediateFalse()
58+
{
59+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
60+
bool v = false;
61+
cookieOptions.HttpOnly = v;
62+
Response.Cookies.Append("auth", "secret", cookieOptions); // BAD
63+
}
64+
65+
void CookieIntermediateFalseInitializer()
66+
{
67+
bool v = false;
68+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = v };
69+
Response.Cookies.Append("auth", "secret", cookieOptions); // BAD
70+
}
71+
}

csharp/test/security/CWE-1004/CookieHttpOnlyFalseAspNetCore/UseCookiePolicyCallback/HttpOnly.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security Features/CWE-1004/CookieWithoutHttpOnly.ql
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.AspNetCore.Http;
5+
6+
public class MyController : Microsoft.AspNetCore.Mvc.Controller
7+
{
8+
public void CookieDefault()
9+
{
10+
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions();
11+
cookieOptions.HttpOnly = false;
12+
Response.Cookies.Append("auth", "secret", cookieOptions); // GOOD: HttpOnly is set in callback
13+
}
14+
}
15+
16+
public class Startup
17+
{
18+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
19+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
20+
{
21+
app.UseCookiePolicy();
22+
}
23+
24+
public void ConfigureServices(IServiceCollection services)
25+
{
26+
services.Configure<CookiePolicyOptions>(options =>
27+
{
28+
options.OnAppendCookie = cookieContext => SetCookies(cookieContext.CookieOptions);
29+
});
30+
}
31+
32+
private void SetCookies(CookieOptions options)
33+
{
34+
options.Secure = true;
35+
options.HttpOnly = true;
36+
}
37+
}
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: --load-sources-from-project:${testdir}/../../../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

0 commit comments

Comments
 (0)