Skip to content

Commit 3a83eaf

Browse files
committed
security: harden namespace handling in legacy bitstream redirect guard
1 parent c1b3493 commit 3a83eaf

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ export const legacyBitstreamURLRedirectGuard: CanActivateFn = (
4848
getFirstCompletedRemoteData(),
4949
map((rd: RemoteData<Bitstream>) => {
5050
if (rd.hasSucceeded && !rd.hasNoContent) {
51-
const nameSpace = appConfig.ui.nameSpace?.replace(/\/$/, '') || '';
52-
const redirectUrl = new URL(nameSpace + `/bitstreams/${rd.payload.uuid}/download`, serverHardRedirectService.getCurrentOrigin()).href;
53-
console.log('Legacy bitstream URL redirecting to:', redirectUrl);
51+
// Harden namespace handling: trim slashes, neutralize absolute-like values, enforce root-relative path
52+
let nameSpace = (appConfig.ui.nameSpace || '').replace(/^\/+|\/+$/g, '');
53+
// Neutralize any absolute-like values (http:, https:, //)
54+
if (nameSpace.startsWith('http:') || nameSpace.startsWith('https:') || nameSpace.startsWith('//')) {
55+
nameSpace = '';
56+
}
57+
// Always build path starting with /
58+
const redirectPath = nameSpace ? `/${nameSpace}/bitstreams/${rd.payload.uuid}/download` : `/bitstreams/${rd.payload.uuid}/download`;
59+
const redirectUrl = new URL(redirectPath, serverHardRedirectService.getCurrentOrigin()).href;
5460
serverHardRedirectService.redirect(redirectUrl, 301);
5561
return false;
5662
} else {

0 commit comments

Comments
 (0)