Skip to content

Commit b8399c0

Browse files
Release/v3.1.0 (#183)
Added CMS13 Support Fix #165
1 parent 4518a0c commit b8399c0

188 files changed

Lines changed: 5553 additions & 140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Jhoose Security - CMS13 Build
2+
3+
on:
4+
push:
5+
branches: [ main, release/* ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
env:
11+
BUILD_NO: 3.1.0.${{ github.run_number }}
12+
BUILD_NO_PRE: 3.1.0-rc.${{ github.run_number }}
13+
14+
jobs:
15+
build:
16+
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- name: Setup .NET
23+
uses: actions/setup-dotnet@v5
24+
with:
25+
dotnet-version: |
26+
10.0.x
27+
28+
- name: Configure Source
29+
working-directory: ./src/Jhoose.Security
30+
run: dotnet nuget add source https://nuget.pkg.github.com/andrewmarkham/index.json --name "GithubBuild" --store-password-in-clear-text --username andrewmarkham --password ${{ secrets.PACKAGE_TOKEN }}
31+
32+
- name: Use Node.js 22.21.0
33+
uses: actions/setup-node@v5
34+
with:
35+
node-version: 22.21.0
36+
37+
- name: Run node
38+
working-directory: ./src/Jhoose.Security/src
39+
run: |
40+
npm install
41+
npm run publish
42+
43+
- name: Build (Production)
44+
if: github.ref == 'refs/heads/main'
45+
run: dotnet build --configuration Release -p:Version=${{ env.BUILD_NO }} -p:CMSVersion=CMS13
46+
working-directory: ./src/Jhoose.Security
47+
48+
- name: Build (Pre Release)
49+
if: github.ref != 'refs/heads/main'
50+
run: dotnet build --configuration PreRelease -p:Version=${{ env.BUILD_NO_PRE }} -p:CMSVersion=CMS13
51+
working-directory: ./src/Jhoose.Security
52+
53+
- name: Run Jhoose.Security.Tests
54+
working-directory: ./src/Tests/Jhoose.Security.Tests
55+
run: dotnet test Jhoose.Security.Tests.csproj --configuration Release --logger "trx;LogFileName=test_results.trx"
56+
57+
- name: Report tests
58+
if: always()
59+
uses: dorny/test-reporter@v3
60+
with:
61+
name: NUnit Tests
62+
path: './src/**/test_results.trx'
63+
reporter: dotnet-trx
64+
65+
- name: nuget push
66+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release')
67+
working-directory: ./src/Jhoose.Security
68+
run: dotnet nuget push "**/Jhoose.Security*.nupkg" -k ${{ env.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/andrewmarkham/index.json --skip-duplicate
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-jhoose-security-core.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/build-jhoose-security.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Jhoose Security
1+
name: Jhoose Security CMS12
22

33
on:
44
push:
@@ -8,19 +8,19 @@ on:
88
workflow_dispatch:
99

1010
env:
11-
BUILD_NO: 3.0.4.${{ github.run_number }}
12-
BUILD_NO_PRE: 3.0.4-rc.${{ github.run_number }}
11+
BUILD_NO: 3.1.0.${{ github.run_number }}
12+
BUILD_NO_PRE: 3.1.0-rc.${{ github.run_number }}
1313

1414
jobs:
1515
build:
1616

1717
runs-on: ubuntu-latest
1818

1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v6
2121

2222
- name: Setup .NET
23-
uses: actions/setup-dotnet@v4
23+
uses: actions/setup-dotnet@v5
2424
with:
2525
dotnet-version: |
2626
8.0.x
@@ -32,7 +32,7 @@ jobs:
3232
run: dotnet nuget add source https://nuget.pkg.github.com/andrewmarkham/index.json --name "GithubBuild" --store-password-in-clear-text --username andrewmarkham --password ${{ secrets.PACKAGE_TOKEN }}
3333

3434
- name: Use Node.js 22.21.0
35-
uses: actions/setup-node@v4
35+
uses: actions/setup-node@v5
3636
with:
3737
node-version: 22.21.0
3838

@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Report tests
6060
if: always()
61-
uses: dorny/test-reporter@v1
61+
uses: dorny/test-reporter@v3
6262
with:
6363
name: NUnit Tests
6464
path: './src/**/test_results.trx'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10071,3 +10071,5 @@ src/Jhoose.Security/src/node_modules/@antv/g6-extension-react/src/react-node/ren
1007110071
src/Tests/PerformanceBenchMarks/bin/Release/net8.0/Jhoose.Security.dll
1007210072
src/Tests/PerformanceBenchMarks/bin/Release/net8.0/Jhoose.Security.pdb
1007310073
src/Tests/PerformanceBenchMarks/bin/Release/net8.0/Jhoose.Security.xml
10074+
src/Sample/Foundation/modules/_protected/Jhoose.Security/ClientResources/csp-app.js
10075+
src/Sample/Foundation/modules/_protected/Jhoose.Security/module.config

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@
4343
"sourceFileMap": {
4444
"/Views": "${workspaceFolder}/src/Sample/Foundation/Views"
4545
}
46+
},
47+
{
48+
"name": "CMS13",
49+
"type": "coreclr",
50+
"request": "launch",
51+
"preLaunchTask": "buildCMS13",
52+
"program": "${workspaceFolder}/src/Sample/CMS13/bin/Debug/net10.0/alloy13preview.dll",
53+
"args": [],
54+
"cwd": "${workspaceFolder}/src/Sample/CMS13",
55+
"stopAtEntry": false,
56+
"serverReadyAction": {
57+
"action": "openExternally",
58+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
59+
},
60+
"env": {
61+
"ASPNETCORE_ENVIRONMENT": "Development"
62+
},
63+
"sourceFileMap": {
64+
"/Views": "${workspaceFolder}/src/Sample/CMS13/Views"
65+
}
4666
}
4767
]
4868
}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@
4343
],
4444
"problemMatcher": "$msCompile"
4545
},
46+
{
47+
"label": "buildCMS13",
48+
"command": "dotnet",
49+
"type": "process",
50+
"args": [
51+
"build",
52+
"${workspaceFolder}/src/Sample/CMS13/alloy13preview.csproj",
53+
"/property:GenerateFullPaths=true",
54+
"/property:CMSVersion=CMS13",
55+
"/consoleloggerparameters:NoSummary"
56+
],
57+
"problemMatcher": "$msCompile"
58+
},
4659
{
4760
"label": "copy",
4861
"command": "cp",

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This module adds several security features to an Optimizely website.
77
- User interface to manage the Recommended Security headers and add to the response headers.
88

99
This module fully supports
10+
- Optimizely 13, .NET (10.0) (From version 3.1.0)
1011
- Optimizely 12, .NET (6.0-8.0) (Up to version 2.5.0)
1112
- Optimizely 12, .NET (8.0-10.0) (From version 2.6.0)
1213
- Episerver 11, .Net Framework 4.7.1 and Optimizely 12, .NET 5.0 [Legacy Documentation](./documentation/Legacy%20README.md)
@@ -18,12 +19,20 @@ This module adds several security features to an Optimizely website.
1819

1920
Install the package directly from the Optimizely NuGet repository.
2021

21-
```
22+
``` bash
23+
# To install CMS12
2224
dotnet add package Jhoose.Security.Admin
23-
```
2425

26+
# To install CMS13
27+
dotnet add package Jhoose.Security.Admin13
2528
```
29+
30+
``` bash
31+
# To install CMS12
2632
Install-Package Jhoose.Security.Admin
33+
34+
# To install CMS13
35+
Install-Package Jhoose.Security.Admin13
2736
```
2837

2938
### Upgrade to V3.0.0
@@ -296,4 +305,5 @@ X-API-Key: ...
296305
|2.6.2|Fixed another bug with (CRLF in header values)|
297306
|2.6.3|Fixed performance issues with the reporting API.<br/>Fixed a race condition that caused the nonce to leak across requests under high load.|
298307
|3.0.0|Added multisite support, CSP and Permissions Policy, Security Headers can now be configured per site. |
299-
|3.0.2|Fixed issue with the files not being copied to the output directory when building the project, this was causing the module to not work when installed from NuGet.|
308+
|3.0.4|Fixed issue with the files not being copied to the output directory when building the project, this was causing the module to not work when installed from NuGet.|
309+
|3.1.0| Added CMS13 Support.|

src/Jhoose.Security/DependencyInjection/SecurityExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44

55
using EPiServer.Authorization;
6-
using EPiServer.ServiceLocation;
6+
77
using EPiServer.Shell.Modules;
88
using Jhoose.Security.Configuration;
99

@@ -41,6 +41,12 @@
4141
using Jhoose.Security.Features.CSP.Repository;
4242
using Jhoose.Security.Features.Core.Providers;
4343

44+
45+
#if CMS12
46+
using EPiServer.ServiceLocation;
47+
#else
48+
using EPiServer.DependencyInjection;
49+
#endif
4450
namespace Jhoose.Security.DependencyInjection;
4551

4652
public static class SecurityExtensions
@@ -151,6 +157,7 @@ public static IServiceCollection AddJhooseSecurity(this IServiceCollection servi
151157

152158
public static IApplicationBuilder UseJhooseSecurity(this IApplicationBuilder applicationBuilder)
153159
{
160+
154161
var securityOptions = applicationBuilder.ApplicationServices.GetService<IOptions<JhooseSecurityOptions>>();
155162

156163
applicationBuilder = applicationBuilder.UseWhen(c => IsValidPath(c.Request, securityOptions?.Value.ExclusionPaths ?? Enumerable.Empty<string>()), ab =>
@@ -172,7 +179,6 @@ public static IApplicationBuilder UseJhooseSecurity(this IApplicationBuilder app
172179

173180
public static bool IsValidPath(HttpRequest request, IEnumerable<string> exclusionPaths)
174181
{
175-
176182
foreach (var path in exclusionPaths)
177183
{
178184
if (request.Path.StartsWithSegments(path, System.StringComparison.InvariantCultureIgnoreCase))
@@ -183,4 +189,4 @@ public static bool IsValidPath(HttpRequest request, IEnumerable<string> exclusio
183189

184190
return true;
185191
}
186-
}
192+
}

src/Jhoose.Security/Features/Core/SecurityRepositoryBase.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ public virtual List<T> Load(string headerName)
3535

3636
var headerList = new List<T>();
3737

38-
foreach (var header in headers)
39-
{
40-
var responseHeader = JsonSerializer.Deserialize<T>(header.Value);
41-
if (responseHeader != null)
38+
try {
39+
foreach (var header in headers)
4240
{
43-
headerList.Add(responseHeader);
41+
var responseHeader = JsonSerializer.Deserialize<T>(header.Value);
42+
if (responseHeader != null)
43+
{
44+
headerList.Add(responseHeader);
45+
}
4446
}
4547
}
48+
catch (JsonException ex)
49+
{
50+
logger.LogError(ex, "Error deserializing response header from database");
51+
}
52+
4653
return headerList;
4754
}
4855

src/Jhoose.Security/Features/Reporting/Controllers/ProblemJsonFormatter.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
2-
2+
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
66

7+
using EPiServer.Formatters;
8+
9+
using Jhoose.Security.Features.Reporting.Models;
10+
711
using Microsoft.AspNetCore.Mvc.Formatters;
812
using Microsoft.Extensions.DependencyInjection;
913
using Microsoft.Extensions.Logging;
@@ -12,16 +16,17 @@
1216

1317
namespace Jhoose.Security.Features.Reporting.Controllers;
1418

15-
public class ProblemJsonFormatter : TextInputFormatter
19+
public class ProblemJsonFormatter : TextInputFormatter, IJsonInputFormatter
1620
{
21+
1722
public ProblemJsonFormatter()
1823
{
19-
2024
this.SupportedMediaTypes.Add(new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/problem+json"));
2125
this.SupportedMediaTypes.Add(new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/reports+json"));
2226
this.SupportedMediaTypes.Add(new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/csp-report"));
2327
this.SupportedEncodings.Add(Encoding.UTF8);
2428
this.SupportedEncodings.Add(Encoding.Unicode);
29+
2530
}
2631

2732
public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding effectiveEncoding)
@@ -52,4 +57,4 @@ public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputForma
5257
return await InputFormatterResult.FailureAsync();
5358
}
5459
}
55-
}
60+
}

0 commit comments

Comments
 (0)