Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit d002d90

Browse files
committed
CSP Adjustments
2 parents 2eac1f7 + 912f52e commit d002d90

File tree

10 files changed

+43
-17
lines changed

10 files changed

+43
-17
lines changed

src/Backend/Jp.Application/AutoMapper/ViewModelToDomainMappingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public ViewModelToDomainMappingProfile()
7070
* Identity Resource commands
7171
*/
7272
CreateMap<IdentityResource, RegisterIdentityResourceCommand>().ConstructUsing(c => new RegisterIdentityResourceCommand(c));
73-
CreateMap<IdentityResource, UpdateIdentityResourceCommand>().ConstructUsing(c => new UpdateIdentityResourceCommand(c));
73+
CreateMap<IdentityResourceViewModel, UpdateIdentityResourceCommand>().ConstructUsing(c => new UpdateIdentityResourceCommand(c,c.OldName));
7474
CreateMap<RemoveIdentityResourceViewModel, RemoveIdentityResourceCommand>().ConstructUsing(c => new RemoveIdentityResourceCommand(c.Name));
7575

7676
/*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using IdentityServer4.Models;
2+
3+
namespace Jp.Application.ViewModels.IdentityResourceViewModels
4+
{
5+
public class IdentityResourceViewModel : IdentityResource
6+
{
7+
public string OldName { get; set; }
8+
}
9+
}

src/Backend/Jp.Domain/CommandHandlers/IdentityResourceCommandHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public async Task<bool> Handle(UpdateIdentityResourceCommand request, Cancellati
6262
NotifyValidationErrors(request);
6363
return false;
6464
}
65-
66-
var savedClient = await _identityResourceRepository.GetByName(request.Resource.Name);
65+
66+
var savedClient = await _identityResourceRepository.GetByName(request.OldIdentityResourceName != request.Resource.Name ? request.OldIdentityResourceName : request.Resource.Name);
6767
if (savedClient == null)
6868
{
6969
await Bus.RaiseEvent(new DomainNotification("1", "Resource not found"));

src/Backend/Jp.Domain/Commands/IdentityResource/IdentityResourceCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Jp.Domain.Commands.IdentityResource
66
public abstract class IdentityResourceCommand : Command
77
{
88
public IdentityServer4.Models.IdentityResource Resource { get; protected set; }
9+
10+
public string OldIdentityResourceName { get; protected set; }
911

1012
}
1113
}

src/Backend/Jp.Domain/Commands/IdentityResource/UpdateIdentityResourceCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ namespace Jp.Domain.Commands.IdentityResource
44
{
55
public class UpdateIdentityResourceCommand : IdentityResourceCommand
66
{
7-
public UpdateIdentityResourceCommand(IdentityServer4.Models.IdentityResource resource)
7+
public UpdateIdentityResourceCommand(IdentityServer4.Models.IdentityResource resource,string oldIdentityResourceName)
88
{
99
Resource = resource;
10+
this.OldIdentityResourceName = oldIdentityResourceName;
1011
}
1112

1213
public override bool IsValid()

src/Backend/Jp.UserManagement/Controllers/IdentityResourceController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public async Task<ActionResult<DefaultResponse<bool>>> Save([FromBody] IdentityR
5454
return Response(true);
5555
}
5656

57-
[HttpPost, Route("update"), Authorize(Policy = "Admin")]
58-
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] IdentityResource model)
57+
[HttpPut, Route("update"), Authorize(Policy = "Admin")]
58+
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] IdentityResourceViewModel model)
5959
{
6060
if (!ModelState.IsValid)
6161
{

src/Frontend/Jp.AdminUI/src/app/panel/identity-resources/edit/identity-resource-edit.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit } from "@angular/core";
22
import { TranslatorService } from "@core/translator/translator.service";
3-
import { flatMap } from "rxjs/operators";
3+
import { flatMap,tap } from "rxjs/operators";
44
import { ActivatedRoute, Router } from "@angular/router";
55
import { ToasterConfig, ToasterService } from "angular2-toaster";
66
import { DefaultResponse } from "@shared/viewModel/default-response.model";
@@ -26,6 +26,7 @@ export class IdentityResourceEditComponent implements OnInit {
2626
});
2727
public showButtonLoading: boolean;
2828
standardClaims: string[];
29+
public name:string;
2930

3031
constructor(
3132
private route: ActivatedRoute,
@@ -35,7 +36,13 @@ export class IdentityResourceEditComponent implements OnInit {
3536
public toasterService: ToasterService) { }
3637

3738
public ngOnInit() {
38-
this.route.params.pipe(flatMap(p => this.identityResourceService.getIdentityResourceDetails(p["name"]))).subscribe(result => this.model = result.data);
39+
40+
this.route.params
41+
.pipe(tap(p => this.name = p["name"]))
42+
.pipe(flatMap(p =>
43+
this.identityResourceService.getIdentityResourceDetails(p["name"])
44+
))
45+
.subscribe(result => this.model = result.data);
3946
this.errors = [];
4047
this.showButtonLoading = false;
4148
this.standardClaims = StandardClaims.claims;
@@ -46,7 +53,7 @@ export class IdentityResourceEditComponent implements OnInit {
4653
this.showButtonLoading = true;
4754
this.errors = [];
4855
try {
49-
56+
this.model.oldName = this.name;
5057
this.identityResourceService.update(this.model).subscribe(
5158
registerResult => {
5259
if (registerResult.data) {

src/Frontend/Jp.AdminUI/src/app/shared/viewModel/identity-resource.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export class IdentityResource {
1313
displayName: string;
1414
description: string;
1515
userClaims: string[];
16+
oldName:string;
1617
}

src/Frontend/Jp.UI.SSO/Configuration/SecurityHeadersConfiguration.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.AspNetCore.HttpOverrides;
4-
using System.Collections.Generic;
54

65
namespace Jp.UI.SSO.Configuration
76
{
87
public static class SecurityHeadersConfiguration
98
{
109
public static void UseSecurityHeaders(this IApplicationBuilder app, IHostingEnvironment env)
1110
{
11+
1212
app.UseForwardedHeaders(new ForwardedHeadersOptions()
1313
{
1414
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
@@ -22,22 +22,28 @@ public static void UseSecurityHeaders(this IApplicationBuilder app, IHostingEnvi
2222
app.UseCsp(options =>
2323
{
2424
options.DefaultSources(o => o.Self());
25+
options.ObjectSources(o => o.None());
26+
options.FrameAncestors(o => o.None());
27+
options.Sandbox(directive => directive.AllowForms().AllowSameOrigin().AllowScripts());
28+
options.BaseUris(configuration => configuration.Self());
2529
options.FrameSources(o => o.Self()
2630
// this custom source can be removed in your build
2731
.CustomSources("https://ghbtns.com"));
28-
options.FrameAncestors(o => o.CustomSources("http:"));
29-
options.StyleSources(o => o.Self());
30-
options.ObjectSources(o => o.None());
32+
33+
if (env.IsProduction())
34+
options.UpgradeInsecureRequests();
3135
options.ImageSources(a =>
3236
{
3337
a.Self();
3438
a.CustomSources = new[] { "data: https:" };
3539
});
3640
options.FontSources(configuration => configuration.Self().CustomSources("https://fonts.googleapis.com/", "https://fonts.gstatic.com/"));
37-
options.ConnectSources(s => s.CustomSources("https://dc.services.visualstudio.com"));
38-
options.ScriptSources(s => s.UnsafeInline().CustomSources("https://az416426.vo.msecnd.net", @"sha256-ZT3q7lL9GXNGhPTB1Vvrvds2xw/kOV0zoeok2tiV23I="));
41+
options.ConnectSources(s => s.Self().CustomSources("https://dc.services.visualstudio.com"));
42+
options.ScriptSources(s => s.Self().UnsafeInline().CustomSources("https://az416426.vo.msecnd.net"));
3943

4044
});
45+
46+
4147
}
4248

4349
}

src/Frontend/Jp.UI.SSO/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Startup(IHostingEnvironment environment, ILogger<Startup> logger)
3030
{
3131
builder.AddUserSecrets<Startup>();
3232
}
33-
33+
3434

3535
Configuration = builder.Build();
3636
_environment = environment;
@@ -86,7 +86,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
8686
app.UseHttpsRedirection();
8787
}
8888

89-
//app.UseSecurityHeaders(env);
89+
app.UseSecurityHeaders(env);
9090
app.UseStaticFiles();
9191
app.UseIdentityServer();
9292
app.UseLocalization();

0 commit comments

Comments
 (0)