Session management is a fundamental component of web applications: despite the apparent simplicity, correctly implementing web sessions is extremely tricky, as witnessed by the large number of existing attacks. This motivated the design of formal methods to rigorously reason about web session security which, however, are not supported at present by suitable automated verification techniques. In this paper we introduce the first security type system that enforces session security on a core model of web applications, focusing in particular on serverside code. We showcase the expressiveness of our type system by analyzing the session management logic of HotCRP, Moodle, and phpMyAdmin, unveiling novel security flaws that have been acknowledged by software developers.1. manage[sid](paper , action, token) ֒→ 2. start @sid; 3. if $user = ⊥ then 4.reply ({auth → form(login, ⊥, ⊥ )}, skip, {}) 5. else if paper = ⊥ then 6.$utoken = fresh(); 7.reply ({add → form(manage, ⊥, submit, x ), 8.del → form(manage , ⊥, withdraw, x )}, skip, {}) 9.with x = $utoken 10. else if tokenchk(token, $utoken) then 11.auth paper , action at ℓ C ; reply ({}, skip, {})