Skip to content

Commit 3e2880a

Browse files
committed
initial sec vulns
1 parent 2929c2a commit 3e2880a

18 files changed

+364
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecurityVulnerabilities", "src\SecurityVulnerabilities\SecurityVulnerabilities.csproj", "{ED481F32-3DEB-4190-B679-DF1B86069C9C}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{ED481F32-3DEB-4190-B679-DF1B86069C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{ED481F32-3DEB-4190-B679-DF1B86069C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{ED481F32-3DEB-4190-B679-DF1B86069C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{ED481F32-3DEB-4190-B679-DF1B86069C9C}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: "3.9"
2+
3+
services:
4+
db:
5+
container_name: postgres
6+
image: postgres:13.6-alpine
7+
environment:
8+
- POSTGRES_DB=a_site_to_order_stuff_local
9+
- POSTGRES_USER=postgres
10+
- POSTGRES_PASSWORD=postgres
11+
ports:
12+
- "5433:5432"
13+
14+
flyway:
15+
container_name: flyway
16+
image: "flyway/flyway:8.5-alpine"
17+
command: -url=jdbc:postgresql://db:5432/a_site_to_order_stuff_local -user=postgres -password=postgres -connectRetries=60 migrate
18+
volumes:
19+
- ./sql/:/flyway/sql
20+
depends_on:
21+
- db
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE customers
2+
(
3+
id SERIAL PRIMARY KEY,
4+
first_name varchar(100) not null,
5+
last_name varchar(100) not null
6+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE documents
2+
(
3+
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
4+
file_path varchar(100) not null
5+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SecurityVulnerabilities.Controllers;
2+
3+
public class Customer
4+
{
5+
public long Id { get; set; }
6+
public string FirstName { get; set; }
7+
public string LastName { get; set; }
8+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Dapper;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Npgsql;
4+
using SecurityVulnerabilities.Controllers;
5+
6+
namespace SecurityVulnerabilities.Customers;
7+
8+
[ApiController]
9+
[Route("[controller]")]
10+
public class SafeCustomersController : ControllerBase
11+
{
12+
private readonly NpgsqlConnection _dbConnection;
13+
14+
public SafeCustomersController(NpgsqlConnection dbConnection)
15+
{
16+
_dbConnection = dbConnection;
17+
}
18+
19+
[HttpGet("{lastName}")]
20+
public Customer Get(string lastName)
21+
{
22+
var query = @"SELECT id,
23+
first_name as FirstName,
24+
last_name as LastName
25+
FROM customers
26+
WHERE last_name=@lastName";
27+
28+
return _dbConnection.QueryFirstOrDefault<Customer>(query, new { lastName});
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Dapper;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Npgsql;
4+
using SecurityVulnerabilities.Controllers;
5+
6+
namespace SecurityVulnerabilities.Customers;
7+
8+
[ApiController]
9+
[Route("[controller]")]
10+
public class VulnerableCustomersController : ControllerBase
11+
{
12+
private readonly NpgsqlConnection _dbConnection;
13+
14+
public VulnerableCustomersController(NpgsqlConnection dbConnection)
15+
{
16+
_dbConnection = dbConnection;
17+
}
18+
19+
[HttpGet("{lastName}")]
20+
public Customer Get(string lastName)
21+
{
22+
var query = $@"SELECT id,
23+
first_name as FirstName,
24+
last_name as LastName
25+
FROM customers
26+
WHERE last_name='{lastName}'";
27+
28+
return _dbConnection.QueryFirstOrDefault<Customer>(query);
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SecurityVulnerabilities.Documents;
2+
3+
public class CreateFileRequest
4+
{
5+
public string FilePath { get; set; }
6+
public string FileContents { get; set; }
7+
}

0 commit comments

Comments
 (0)