Skip to content

Commit c78ecc7

Browse files
authored
Add static analysis tool (#290)
- Add SecurityCodeScan as NuGet dependency (during build, not install) - Add SecurityCodeScan as CI step - Makefile command for security scan (must run manually) - Fix some linting
1 parent 0b606c4 commit c78ecc7

File tree

10 files changed

+55
-22
lines changed

10 files changed

+55
-22
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ jobs:
1414
- uses: actions/checkout@v3
1515
- name: Check dotnet Style
1616
run: dotnet-format --check --exclude /
17+
security:
18+
runs-on: windows-2022
19+
steps:
20+
- name: Install security-code-scan
21+
run: dotnet tool install -g security-scan
22+
- uses: actions/checkout@v3
23+
- name: Run security analysis
24+
run: security-scan EasyPost.sln --ignore-msbuild-errors --verbose
25+
# "--ignore-msbuild-errors" needed since MSBuild does not like F#: https://github.com/security-code-scan/security-code-scan/issues/235
26+
# In the future, we can collect the output logs by enabling Code Scanning and using the pre-built GitHub Action: https://github.com/marketplace/actions/securitycodescan
27+
# https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github#uploading-a-code-scanning-analysis-with-github-actions
1728
NET_Tests:
1829
# derived from https://dev.to/felipetofoli/github-actions-for-net-full-framework-build-and-test-299h
1930
runs-on: windows-2022

EasyPost.Tests.FSharp/EasyPost.Tests.FSharp.fsproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
18-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
19-
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
18+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8"/>
19+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8"/>
20+
<PackageReference Include="SecurityCodeScan.VS2019" Version="[5.0.0, 6.0.0)">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
2024
</ItemGroup>
2125

2226
</Project>

EasyPost.Tests.VB/EasyPost.Tests.VB.vbproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
14-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
15-
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
14+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8"/>
15+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8"/>
16+
<PackageReference Include="SecurityCodeScan.VS2019" Version="[5.0.0, 6.0.0)">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
1620
</ItemGroup>
1721

1822
</Project>

EasyPost.Tests/EasyPost.Tests.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="EasyVCR" Version="0.3.1" />
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
17-
<PackageReference Include="coverlet.collector" Version="1.2.0" />
18-
<PackageReference Include="Newtonsoft.Json" Version="[13.0.1, 14.0.0)" />
19-
<PackageReference Include="RestSharp" Version="[107.3.0, 108.0.0)" />
20-
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
21-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
15+
<PackageReference Include="EasyVCR" Version="0.3.1"/>
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
17+
<PackageReference Include="coverlet.collector" Version="1.2.0"/>
18+
<PackageReference Include="Newtonsoft.Json" Version="[13.0.1, 14.0.0)"/>
19+
<PackageReference Include="RestSharp" Version="[107.3.0, 108.0.0)"/>
20+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8"/>
21+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8"/>
22+
<PackageReference Include="SecurityCodeScan.VS2019" Version="[5.0.0, 6.0.0)">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
</PackageReference>
2226
</ItemGroup>
2327

2428
<ItemGroup>

EasyPost/Base/Address.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using Newtonsoft.Json;
43

54
namespace EasyPost.Base

EasyPost/EasyPost.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
<ItemGroup>
6262
<PackageReference Include="Newtonsoft.Json" Version="[13.0.1, 14.0.0)"/>
6363
<PackageReference Include="RestSharp" Version="[107.3.0, 108.0.0)"/>
64+
<PackageReference Include="SecurityCodeScan.VS2019" Version="[5.0.0, 6.0.0)">
65+
<PrivateAssets>all</PrivateAssets>
66+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
67+
</PackageReference>
6468
</ItemGroup>
6569

6670
</Project>

EasyPost/Exception.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Runtime.Serialization;
4-
using System.Security.Permissions;
54

65
namespace EasyPost
76
{
@@ -52,14 +51,14 @@ public class PropertyMissing : Exception
5251
{
5352
private readonly string _property;
5453

55-
public PropertyMissing(string property)
54+
public override string Message
5655
{
57-
_property = property;
56+
get { return $"Missing {_property}"; }
5857
}
5958

60-
public override string Message
59+
public PropertyMissing(string property)
6160
{
62-
get { return $"Missing {_property}"; }
61+
_property = property;
6362
}
6463
}
6564

EasyPost/Pickup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4-
using EasyPost.Utilities;
54
using Newtonsoft.Json;
65
using RestSharp;
76

EasyPost/Shipment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading.Tasks;
54
using EasyPost.Utilities;
65
using Newtonsoft.Json;

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ build:
2424
install-cert:
2525
scripts\install_cert.bat ${cert} ${pass}
2626

27+
## install-scanner - Install SecurityCodeScan to your system
28+
install-scanner:
29+
dotnet tool install -g security-scan
30+
2731
## sign - Sign all generated DLLs and NuGet packages with the provided certificate (Windows only)
2832
# @parameters:
2933
# cert= - The certificate to use for signing the built assets.
@@ -56,4 +60,10 @@ test:
5660
lint-scripts:
5761
scripts\lint_scripts.bat
5862

59-
.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test lint-scripts
63+
## scan - Scan the project for security issues (must run install-scanner first)
64+
# Makefile cannot access global dotnet tools, so you need to run the below command manually.
65+
scan:
66+
security-scan --verbose --no-banner --ignore-msbuild-errors EasyPost.sln
67+
# "--ignore-msbuild-errors" needed since MSBuild does not like F#: https://github.com/security-code-scan/security-code-scan/issues/235
68+
69+
.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test lint-scripts install-scanner scan

0 commit comments

Comments
 (0)