Accepting selected projects for Q2 2024 Check availability →
SERVER 02SYSTEM ONLINELAST SYNC: 03:17:44RSS 2.0 — ONLINE
HALF ASSEDTECHNICAL NOTES_
EST. 1999ISSUE 04.2BEST VIEWED AT 1024 × 768
TECHNICAL NOTES / TECHNICAL NOTES / APPLICATION SECURITY / RECORD c5a97e
[APPLICATION SECURITY]NOTE

Checking the lifecycle of a PHP 5.1 login session

POSTED: 13.07.2006AUTHOR: ADMIN2 MIN READCOMMENTS: 0

A login session connects successive requests to server-side authentication state. Treat its identifier as a credential: anyone able to present a valid authenticated identifier may be able to use the same account.

Keep identifiers out of links

Configure session.use_only_cookies and disable transparent session-ID rewriting for the application. Set cookie parameters before session_start and choose the narrowest useful path and domain. Keep the authenticated area on HTTPS and set the Secure cookie flag. A secure login form followed by authenticated pages over ordinary HTTP leaves the session exposed in transit.

Create a new identifier after authentication

Regenerate the session identifier when login succeeds, before assigning authenticated privileges to the new session. Check for failure rather than continuing with an unchanged identifier. Ensure an earlier identifier cannot acquire the new authentication state. Test multiple tabs and interrupted requests, and store session files in a protected location outside the document root.

Enforce expiry and logout in the application

Record activity and enforce an idle limit on the server instead of relying solely on cookie expiry or probabilistic garbage collection. Logout should clear the session state, destroy its stored record and expire the cookie using the same path and domain settings. Check authorisation on every protected request. Try reusing the old identifier after logout to verify that it no longer grants access.

TEST RECORD

Use two independent browser sessions to check login, expiry and logout. Avoid recording complete session identifiers in routine access or debugging logs.

References

PHP manual: session_regenerate_id

PHP manual: session_set_cookie_params

PHP manual: session_destroy