Skip to content

Commit

Permalink
Add CSRF token to protect unauthenticated requests
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisjacquet committed Apr 25, 2022
1 parent ec3f70c commit 3c23d83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -58,6 +58,7 @@ Changes in 9.0
- JS add DOMPurify 2.3.6 in assets/js/DOMPurify/ & Gruntfile.js
- JS fix stored XSS issue related to MarkDown in warehouse.js & plugins.min.js, thanks to @intrapus
- JS remove logged in check on history back in warehouse.js & plugins.min.js
- Add CSRF token to protect unauthenticated requests in Warehouse.php & login.php, thanks to @khanhchauminh

Changes in 8.9.5
----------------
Expand Down
11 changes: 11 additions & 0 deletions Warehouse.php
Expand Up @@ -148,6 +148,17 @@

session_start();

if ( empty( $_SESSION['token'] ) )
{
/**
* Add CSRF token to protect unauthenticated requests
*
* @since 9.0
* @link https://stackoverflow.com/questions/5207160/what-is-a-csrf-token-what-is-its-importance-and-how-does-it-work
*/
$_SESSION['token'] = bin2hex( openssl_random_pseudo_bytes( 16 ) );
}

if ( empty( $_SESSION['STAFF_ID'] )
&& empty( $_SESSION['STUDENT_ID'] )
&& ( basename( $_SERVER['SCRIPT_NAME'] ) === 'Modules.php'
Expand Down
8 changes: 8 additions & 0 deletions index.php
Expand Up @@ -92,6 +92,14 @@
elseif ( isset( $_COOKIE['RosarioSIS'] ) )
{
session_regenerate_id( true ); // And invalidate old session.

/**
* Add CSRF token to protect unauthenticated requests
*
* @since 9.0
* @link https://stackoverflow.com/questions/5207160/what-is-a-csrf-token-what-is-its-importance-and-how-does-it-work
*/
$_SESSION['token'] = bin2hex( openssl_random_pseudo_bytes( 16 ) );
}

// Fix SQL error value too long for type character varying(100).
Expand Down

0 comments on commit 3c23d83

Please sign in to comment.