Skip to content

Commit

Permalink
MDL-76166 auth: Ensure user is in server access logs
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Nov 30, 2022
1 parent 57c1e97 commit 825d11e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/classes/session/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ public static function set_user(\stdClass $user) {

// Init session key.
sesskey();

// Make sure the user is correct in web server access logs.
set_access_log_user();
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/classes/shutdown_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public static function register_function($callback, array $params = null): void
public static function shutdown_handler() {
global $DB;

// Always ensure we know who the user is in access logs even if they
// were logged in a weird way midway through the request.
set_access_log_user();

// Custom stuff first.
foreach (self::$callbacks as $data) {
list($callback, $params) = $data;
Expand Down
2 changes: 1 addition & 1 deletion lib/setuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ function set_access_log_user() {
apache_note('MOODLEUSER', $logname);
}

if ($logmethod == 'header') {
if ($logmethod == 'header' && !headers_sent()) {
header("X-MOODLEUSER: $logname");
}
}
Expand Down

0 comments on commit 825d11e

Please sign in to comment.