Web security involves authentication, which verifies a user's identity, and authorization, which determines what resources a user can access. Traditionally, session-based authentication stored data on the server-side, but modern stateless authentication uses tokens passed in requests. Cookies and tokens maintain state at the client-side in a stateless manner. Libraries can help with authorization rules, roles, and multi-factor authentication.