Secure development

Implementing session rotation, expiry and revocation

Access lifetime: key, clock, server arranged to illustrate implementing session rotation, expiry and revocation.

Implementing session rotation, expiry and revocation connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding session rotation and expiry and revocation helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Session and token controls preserve an authentication decision over time. They need a defined scope, lifetime and invalidation policy. A token should be accepted because a trusted service has verified the relevant properties, not simply because its structure looks familiar.

A web session is a sequence of network HTTP request and response transactions associated with the same user. Modern and complex web applications require the retaining of information or status about each user for the duration of multiple requests. Therefore, sessions provide the ability to establish variables – such as access rights and localization settings – which will apply to each and every interaction a user has with the web application for the duration of the session.

Web applications can create sessions to keep track of anonymous users after the very first user request. An example would be maintaining the user language preference. Additionally, web applications will make use of sessions once the user has authenticated. This ensures the ability to identify the user on any subsequent requests as well as being able to apply security access controls, authorised access to the user private data, and to increase the usability of the application. Therefore, current web applications can provide session capabilities both pre and post authentication.

Why it matters

Consider a realistic failure: an application rotates one session credential but leaves alternate tokens or cached access working.

A reusable credential can let someone continue acting as an account after the intended access should have ended. Long-lived access, excessive token contents and inconsistent revocation can increase the exposure beyond the initial event.

Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.

How penetration testers check for it

Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.

  • Review token creation, transport, storage and acceptance.
  • Check issuer, intended recipient, lifetime and required claims.
  • Test logout, permission changes and credential replacement.
  • Inspect replay and concurrent use according to the documented design.

How to fix it

Use the appropriate maintained mechanisms and verify the result in the actual production configuration.

  • If a web application generates session IDs with 64 bits of entropy, an attacker can expect to spend approximately 585 years to successfully guess a valid session ID, assuming the attacker can try 10,000 guesses per second with 100,000 valid simultaneous sessions available in the application.
  • Further analysis of the expected time for an attacker to brute-force session identifiers is available here.
  • More information about the relationship between Session ID Length and Session ID Entropy is available here.
  • Even if a web application makes use of cookies as its default session ID exchange mechanism, it might accept other exchange mechanisms too.
  • Rotate and revoke according to the session model.
  • Keep credentials out of unnecessary URLs, logs and persistent copies.

Some designs intentionally use short-lived credentials without immediate global revocation. Assess the complete lifetime and access model before calling that design a failure.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss secure development and code review.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo