77require_once $ _SERVER ['DOCUMENT_ROOT ' ].'/php/templates/language/lang.php ' ;
88require_once $ _SERVER ['DOCUMENT_ROOT ' ].'/php/templates/security.php ' ;
99
10+ // if (session_status() === PHP_SESSION_NONE) {
11+ // session_start();
12+ // }
13+
1014session_start ();
1115
1216const COOKIE_NAME = 'NetAlertX_SaveLogin ' ;
@@ -25,10 +29,13 @@ function validate_local_path(?string $encoded): string {
2529 if (!$ encoded ) return DEFAULT_REDIRECT ;
2630
2731 $ decoded = base64_decode ($ encoded , true );
28- if ($ decoded === false ) return DEFAULT_REDIRECT ;
32+ if ($ decoded === false ) {
33+ return DEFAULT_REDIRECT ;
34+ }
2935
30- // strict local path check
31- if (!preg_match ('#^/[a-zA-Z0-9_\-/\.]*$# ' , $ decoded )) {
36+ // strict local path check (allow safe query strings + fragments)
37+ // Using ~ as the delimiter instead of #
38+ if (!preg_match ('~^(?!//)(?!.*://)/[a-zA-Z0-9_\-./?=&:%#]*$~ ' , $ decoded )) {
3239 return DEFAULT_REDIRECT ;
3340 }
3441
@@ -74,7 +81,9 @@ function logout_user(): void {
7481===================================================== */
7582
7683if ($ nax_WebProtection !== 'true ' ) {
77- login_user ();
84+ if (!is_authenticated ()) {
85+ login_user ();
86+ }
7887 safe_redirect (append_hash ($ redirectTo ));
7988}
8089
@@ -190,7 +199,11 @@ function logout_user(): void {
190199 <!-- /.login-logo -->
191200 <div class="login-box-body">
192201 <p class="login-box-msg"><?= lang ('Login_Box ' );?> </p>
193- <form action="index.php<?php echo !empty ($ _GET ['next ' ]) ? '?next= ' . htmlspecialchars ($ _GET ['next ' ]) : '' ; ?> " method="post">
202+ <form action="index.php<?php
203+ echo !empty ($ _GET ['next ' ])
204+ ? '?next= ' . htmlspecialchars ($ _GET ['next ' ], ENT_QUOTES , 'UTF-8 ' )
205+ : '' ;
206+ ?> " method="post">
194207 <div class="form-group has-feedback">
195208 <input type="hidden" name="url_hash" id="url_hash">
196209 <input type="password" class="form-control" placeholder="<?= lang ('Login_Psw-box ' );?> " name="loginpassword">
0 commit comments