diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-18 09:16:33 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-18 09:16:33 +0100 |
| commit | 906652278bb77eb33d42726d5bc5f1e2d020c584 (patch) | |
| tree | 5f6d8a540783cc89d624bceb9fa611c8a1c5bab8 | |
| parent | 62662b7d0bb81f5b9a292a192f8888a3987af8eb (diff) | |
| download | bitweaver-906652278bb77eb33d42726d5bc5f1e2d020c584.tar.gz bitweaver-906652278bb77eb33d42726d5bc5f1e2d020c584.tar.bz2 bitweaver-906652278bb77eb33d42726d5bc5f1e2d020c584.zip | |
Extend auth_request checking to correctly handle user role filter
| -rwxr-xr-x | config/kernel/auth_check.php | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/config/kernel/auth_check.php b/config/kernel/auth_check.php index 18de119..15b7ebc 100755 --- a/config/kernel/auth_check.php +++ b/config/kernel/auth_check.php @@ -2,32 +2,31 @@ // Minimal session check - no framework bootstrap include 'auth_config.php'; -if( !empty( $_SESSION['user_role'] ) && $_SESSION['user_role'] > 0 ) { - http_response_code(200); - exit; -} - -// anonymous - check content_id from URI preg_match( '|/attachments/\d+/(\d+)/|', $_SERVER['REQUEST_URI'], $matches ); if( !empty( $matches[1] ) ) { $contentId = (int)$matches[1]; try { $pdo = new PDO( $gBitDbHost, $gBitDbUser, $gBitDbPassword ); - $stmt = $pdo->prepare( - "SELECT COUNT(*) FROM LIBERTY_CONTENT_ROLE_MAP - WHERE content_id = ?", - ); + + // get the role restriction for this content, if any + $stmt = $pdo->prepare( "SELECT ROLE_ID FROM LIBERTY_CONTENT_ROLE_MAP WHERE CONTENT_ID = ?" ); $stmt->execute( [$contentId] ); - if( $stmt->fetchColumn() == 0 ) { + $requiredRoleId = $stmt->fetchColumn(); + + if( $requiredRoleId === false ) { + // no restriction - public content + http_response_code( 200 ); + } elseif( in_array( (int)$requiredRoleId, $_SESSION['user_role'] ?? [] ) ) { http_response_code( 200 ); } else { http_response_code( 403 ); } } catch( PDOException $e ) { - // db failure - deny access safely http_response_code( 403 ); - exit; } exit; -}
\ No newline at end of file +} + +// no content_id in URI - nothing to restrict +http_response_code( 200 );
\ No newline at end of file |
