Skip to content

Commit bf23e06

Browse files
1 parent 0d1416e commit bf23e06

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

app/webapp/controller/View1.controller.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,34 @@ sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/mvc/XMLView", "sap/ui/
250250
}
251251
}
252252
)
253+
254+
// Security: URL validation function to prevent open redirect attacks
255+
function isValidRedirectURL(url) {
256+
if (!url) return false;
257+
258+
try {
259+
// Parse URL relative to current origin
260+
const parsed = new URL(url, window.location.origin);
261+
262+
// Only allow same-origin URLs (relative or absolute to same domain)
263+
if (parsed.origin !== window.location.origin) {
264+
console.error('Security: Blocked redirect to different origin:', url);
265+
return false;
266+
}
267+
268+
// Block dangerous protocols
269+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
270+
console.error('Security: Blocked redirect with invalid protocol:', parsed.protocol);
271+
return false;
272+
}
273+
274+
return true;
275+
} catch (e) {
276+
console.error('Security: Invalid URL format:', url, e);
277+
return false;
278+
}
279+
}
280+
253281
let oCrossAppNavigator;
254282
switch (args[0]) {
255283
case 'SET_SIZE_LIMIT':
@@ -380,10 +408,24 @@ sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/mvc/XMLView", "sap/ui/
380408
});
381409
break;
382410
case 'LOCATION_RELOAD':
383-
window.location = args[1];
411+
// Security: Validate URL before redirect
412+
if (isValidRedirectURL(args[1])) {
413+
window.location = args[1];
414+
} else {
415+
sap.m.MessageBox.error('Invalid redirect URL. Only relative URLs to the same domain are allowed.');
416+
}
384417
break;
385418
case 'OPEN_NEW_TAB':
386-
window.open(args[1], '_blank');
419+
// Security: Validate URL before opening new tab
420+
if (isValidRedirectURL(args[1])) {
421+
const newWindow = window.open(args[1], '_blank');
422+
// Security: Prevent window.opener exploit
423+
if (newWindow) {
424+
newWindow.opener = null;
425+
}
426+
} else {
427+
sap.m.MessageBox.error('Invalid URL. Only relative URLs to the same domain are allowed.');
428+
}
387429
break;
388430
case 'POPUP_CLOSE':
389431
z2ui5.oController.PopupDestroy();

0 commit comments

Comments
 (0)