File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 2525require_once __DIR__ . "/../resources/lib/exceptions/EncodingUnknownException.php " ;
2626require_once __DIR__ . "/../resources/lib/exceptions/EncodingConversionException.php " ;
2727
28+ use UnityWebPortal \lib \CSRFToken ;
2829use UnityWebPortal \lib \UnityGroup ;
2930use UnityWebPortal \lib \UnityHTTPD ;
3031use UnityWebPortal \lib \UnitySQL ;
@@ -97,7 +98,7 @@ function switchUser(
9798 ensure (!is_null ($ USER ));
9899}
99100
100- function http_post (string $ phpfile , array $ post_data ): void
101+ function http_post (string $ phpfile , array $ post_data, bool $ do_generate_csrf_token = true ): void
101102{
102103 global $ LDAP ,
103104 $ SQL ,
@@ -115,6 +116,9 @@ function http_post(string $phpfile, array $post_data): void
115116 $ _SERVER ["REQUEST_METHOD " ] = "POST " ;
116117 $ _SERVER ["PHP_SELF " ] = preg_replace ("/.*webroot\// " , "/ " , $ phpfile );
117118 $ _SERVER ["REQUEST_URI " ] = preg_replace ("/.*webroot\// " , "/ " , $ phpfile ); // Slightly imprecise because it doesn't include get parameters
119+ if (!array_key_exists ("csrf_token " , $ post_data ) && $ do_generate_csrf_token ) {
120+ $ post_data ["csrf_token " ] = CSRFToken::generate ();
121+ }
118122 $ _POST = $ post_data ;
119123 ob_start ();
120124 $ post_did_redirect_or_die = false ;
You can’t perform that action at this time.
0 commit comments