@@ -384,7 +384,47 @@ function authorizePostProcessing($argsObj,$op) {
384
384
echo json_encode (array ('success ' => true ));
385
385
} else {
386
386
// If destination param is set redirect to given page ...
387
- if (!empty ($ argsObj ->destination ) && preg_match ("/linkto.php/ " , $ argsObj ->destination )) {
387
+ if ( !empty ($ argsObj ->destination ) ) {
388
+
389
+ // 1) remove host.port from TL_BASE_HREF -> base_folder
390
+ // https://hsgdshdjs:80/bsbsbb
391
+ // http://fjljfld:8080/Hhhhs
392
+ // http://hjhsjdhshdk/
393
+ $ baseURL = str_replace (':// ' ,': ' ,TL_BASE_HREF );
394
+ $ basePieces = explode (': ' ,TL_BASE_HREF );
395
+ $ howManyPieces = count ($ basePieces );
396
+ switch ($ howManyPieces ) {
397
+ case 2 :
398
+ case 3 :
399
+ break ;
400
+ default :
401
+ echo 'Security Check Failure ' ;
402
+ die ();
403
+ break ;
404
+ }
405
+
406
+ // http: hjhsjdhshdk/
407
+ // http: hjhsjdhshdk/base_folder
408
+ // https: hsgdshdjs: >> 80/bsbsbb
409
+ // http: fjljfld: >> 8080/Hhhhs
410
+ $ dummy = explode ('/ ' ,$ basePieces [$ howManyPieces -1 ]);
411
+ $ baseFolder = '/ ' ;
412
+ $ compo = trim ($ dummy [1 ]);
413
+ if ($ compo != '' ) {
414
+ $ baseFolder .= $ compo . '/ ' ;
415
+ }
416
+
417
+ // 2) check base_folder/linkto.php
418
+ $ where = strpos ($ argsObj ->destination , $ baseFolder . 'linkto.php ' );
419
+ $ checkOK = ($ where !== false ) && ($ where == 0 );
420
+ if ($ checkOK == false ) {
421
+ echo 'Security Check Failure ' ;
422
+ die ();
423
+ }
424
+
425
+ // 3) validate content after linkto.php?
426
+ $ dummy = explode ($ baseFolder . 'linkto.php? ' );
427
+ $ afterLinkTo = $ baseFolder . 'linkto.php? ' . cleanInput ($ dummy [1 ]);
388
428
redirect ($ argsObj ->destination );
389
429
} else {
390
430
// ... or show main page
@@ -429,3 +469,18 @@ function processAjaxCheck(&$dbHandler) {
429
469
'timeout_info ' => lang_get ('timeout_info ' )));
430
470
431
471
}
472
+
473
+
474
+ // from https://css-tricks.com/snippets/php/sanitize-database-inputs/
475
+ function cleanInput ($ input ) {
476
+
477
+ $ search = array (
478
+ '@<script[^>]*?>.*?</script>@si ' , // Strip out javascript
479
+ '@<[\/\!]*?[^<>]*?>@si ' , // Strip out HTML tags
480
+ '@<style[^>]*?>.*?</style>@siU ' , // Strip style tags properly
481
+ '@<![\s\S]*?--[ \t\n\r]*>@ ' // Strip multi-line comments
482
+ );
483
+
484
+ $ output = preg_replace ($ search , '' , $ input );
485
+ return $ output ;
486
+ }
0 commit comments