Skip to content

Commit bf31701

Browse files
updates
1 parent 60fc1f4 commit bf31701

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

DocuSign.MyAPI/ClientApp/src/app/core/errorhandler.inteceptor.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,15 @@ export class ErrorHanlderInterceptor implements HttpInterceptor {
4040
} else if (error.status === 401) {
4141
this.translateService.get('ERRORS.401').subscribe((res: string) => {
4242
let snackBarRef = this.notificationService.showInfo(res);
43+
4344
snackBarRef.afterDismissed().subscribe(() => {
44-
const allowedHosts = ['myapicalls.sampleapps.docusign.com', 'myapicalls-t.sampleapps.docusign.com']; // Add allowed hostnames here
4545
let returnUrl = this.router.url;
46-
console.log('returnUrl:', returnUrl); // This will show in the browser console
47-
try {
48-
const url = new URL(returnUrl, window.location.origin);
49-
if (!allowedHosts.includes(url.hostname)) {
50-
returnUrl = '/'; // fallback to home if not allowed
51-
}
52-
} catch {
46+
// Only allow relative paths
47+
if (!returnUrl.startsWith('/')) {
5348
returnUrl = '/';
5449
}
55-
56-
window.location.href = `/account/login?returnUrl=${encodeURIComponent(returnUrl)}`;
50+
window.location.href =
51+
'/account/login?returnUrl=' + returnUrl;
5752
});
5853
});
5954
}

DocuSign.MyAPI/ClientApp/src/app/header/header.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ export class AppHeaderComponent implements OnInit {
1717
) {}
1818

1919
ngOnInit(): void {
20-
this.router.events.subscribe((event) => {
21-
if (event instanceof NavigationEnd) {
22-
this.url = this.router.url;
20+
this.router.events.subscribe((event) => {
21+
if (event instanceof NavigationEnd) {
22+
let currentUrl = this.router.url;
23+
// Only allow relative paths
24+
if (currentUrl.startsWith('/')) {
25+
this.url = currentUrl;
26+
} else {
27+
this.url = '/';
2328
}
24-
});
25-
}
29+
}
30+
});
31+
}
2632
get isLoggedIn(): Observable<boolean> {
2733
return this.accountService.isLoggedIn();
2834
}

DocuSign.MyAPI/Controllers/AccountController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public async Task<ActionResult<String>> GetAccountId()
2727
[Route("login")]
2828
public IActionResult Login(string returnUrl = "/")
2929
{
30+
if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
31+
{
32+
returnUrl = "/";
33+
}
34+
3035
return Challenge(new AuthenticationProperties() { RedirectUri = returnUrl, AllowRefresh = true });
3136
}
3237

0 commit comments

Comments
 (0)