Skip to content

Commit 2992309

Browse files
authored
Merge pull request #11 from secure-web-apps/feature/fix-sonarqube-cloud-findings
Fix SonarQube Cloud findings
2 parents b3fe525 + 36bb70c commit 2992309

8 files changed

Lines changed: 24 additions & 18 deletions

File tree

.github/workflows/deploy-to-azure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
with:
6363
name: dotnet-app
6464
path: ./temp
65-
include-hidden-files: true
65+
include-hidden-files: true # otherwise .well-known folder is not included
6666

6767
iac_plan:
6868
name: IaC (Terraform) Plan

Bff.ServiceDefaults/Extensions.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where
3535
http.AddServiceDiscovery();
3636
});
3737

38-
// Uncomment the following to restrict the allowed schemes for service discovery.
39-
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
40-
// {
41-
// options.AllowedSchemes = ["https"];
42-
// });
38+
builder.Services.Configure<ServiceDiscoveryOptions>(options =>
39+
{
40+
options.AllowedSchemes = ["https"];
41+
});
4342

4443
return builder;
4544
}
@@ -68,8 +67,6 @@ public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) w
6867
!context.Request.Path.StartsWithSegments(HealthEndpointPath)
6968
&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
7069
)
71-
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
72-
//.AddGrpcClientInstrumentation()
7370
.AddHttpClientInstrumentation();
7471
});
7572

server/Controllers/AccountController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public ActionResult Login(string? returnUrl, string? claimsChallenge)
2727
/// [ValidateAntiForgeryToken] // not needed explicitly due the the Auto global definition.
2828
/// </summary>
2929
/// <returns></returns>
30-
[IgnoreAntiforgeryToken] // need to apply this to the form post request
3130
[Authorize]
3231
[HttpPost("Logout")]
3332
public IActionResult Logout()

server/Pages/Error.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<head>
88
<meta charset="utf-8" />
9-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
1010
<title>Error</title>
1111
</head>
1212

ui/src/app/getCookie.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ export const getCookie = (cookieName: string) => {
22
const name = `${cookieName}=`;
33
const decodedCookie = decodeURIComponent(document.cookie);
44
const ca = decodedCookie.split(";");
5-
for (let i = 0; i < ca.length; i += 1) {
6-
let c = ca[i];
7-
while (c.charAt(0) === " ") {
5+
for (let c of ca) {
6+
while (c.startsWith(" ")) {
87
c = c.substring(1);
98
}
10-
if (c.indexOf(name) === 0) {
9+
if (c.startsWith(name)) {
1110
return c.substring(name.length, c.length);
1211
}
1312
}

ui/src/app/home.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
(userProfileClaims?.isAuthenticated) {
1919
<form method="post" action="api/Account/Logout">
2020
<button class="btn btn-outline btn-danger" type="submit">Sign out</button>
21+
<input
22+
type="hidden"
23+
id="__RequestVerificationToken"
24+
name="__RequestVerificationToken"
25+
[value]="getXsrfToken()"
26+
/>
2127
</form>
2228
} @else {
2329
<a class="btn btn-outline-success btn-outline" href="api/Account/Login">Log in</a>

ui/src/app/home.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CommonModule } from '@angular/common';
22
import { HttpClient } from '@angular/common/http';
33
import { Component, OnInit, inject } from '@angular/core';
44
import { Observable } from 'rxjs';
5+
import { getCookie } from './getCookie';
56

67
interface Claim {
78
type: string;
@@ -31,6 +32,10 @@ export class HomeComponent implements OnInit {
3132
this.getUserProfile();
3233
}
3334

35+
getXsrfToken(): string {
36+
return getCookie('XSRF-RequestToken');
37+
}
38+
3439
getUserProfile() {
3540
this.userProfileClaims$ = this.httpClient.get<UserProfile>(
3641
`${this.getCurrentHost()}/api/User`
@@ -50,8 +55,8 @@ export class HomeComponent implements OnInit {
5055
}
5156

5257
private getCurrentHost() {
53-
const host = window.location.host;
54-
const url = `${window.location.protocol}//${host}`;
58+
const host = globalThis.location.host;
59+
const url = `${globalThis.location.protocol}//${host}`;
5560

5661
return url;
5762
}

ui/src/app/secure-api.interceptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function getApiUrl() {
2828
}
2929

3030
function getCurrentHost() {
31-
const host = window.location.host;
32-
const url = `${window.location.protocol}//${host}`;
31+
const host = globalThis.location.host;
32+
const url = `${globalThis.location.protocol}//${host}`;
3333
return url;
3434
}

0 commit comments

Comments
 (0)