Where Did It Come From, Where Did It Go? What the Heck is an OAuth Flow?

Laura Wratten (Application Security Engineer · Canva), Angus Cornall (Application Security Engineer · Canva)

purplecon 2024 · Day 1 · Main Room

Overview

In an increasingly interconnected digital landscape, the secure delegation of access to online services is paramount. Applications frequently need to interact with other platforms on behalf of users, necessitating robust mechanisms that avoid the pitfalls of direct password sharing. This talk, "Where Did It Come From, Where Did It Go? What the Heck is an OAuth Flow?", delivered by Laura Wratten and Angus Cornall, Application Security Engineers at Canva, demystifies OAuth (Open Authorization) and OpenID Connect (OIDC), two foundational protocols enabling this secure delegation and identity verification. The speakers, in their debut conference appearance, adeptly break down the complexities of these standards, tracing their evolution and highlighting critical security considerations.

Watch on YouTube

Visual summary for Where Did It Come From, Where Did It Go? What the Heck is an OAuth Flow? by Laura Wratten, Angus Cornall
Visual summary for Where Did It Come From, Where Did It Go? What the Heck is an OAuth Flow? by Laura Wratten, Angus Cornall

Key moments

  1. 2:00 The insecure 'password sharing' era
  2. 4:15 Introducing OAuth and access tokens
  3. 7:30 Why the convoluted token exchange step?
  4. 8:30 Limitations of OAuth 1.0 leading to 2.0
  5. 12:00 Crucial state validation in OAuth 2.0
  6. 13:30 Demonstrating a lack of state validation attack
  7. 16:30 How OpenID Connect enables social logins
  8. 18:30 Key takeaways and future considerations

Where Did It Come From, Where Did It Go? What the Heck is an OAuth Flow?

Speakers: Laura Wratten (Application Security Engineer, Canva), Angus Cornall (Application Security Engineer, Canva)

Conference: purplecon

YouTube: https://www.youtube.com/watch?v=VnGvHk-0Nuc

Overview

In an increasingly interconnected digital landscape, the secure delegation of access to online services is paramount. Applications frequently need to interact with other platforms on behalf of users, necessitating robust mechanisms that avoid the pitfalls of direct password sharing. This talk, "Where Did It Come From, Where Did It Go? What the Heck is an OAuth Flow?", delivered by Laura Wratten and Angus Cornall, Application Security Engineers at Canva, demystifies OAuth (Open Authorization) and OpenID Connect (OIDC), two foundational protocols enabling this secure delegation and identity verification. The speakers, in their debut conference appearance, adeptly break down the complexities of these standards, tracing their evolution and highlighting critical security considerations.

The presentation provides a comprehensive journey from the rudimentary and insecure practice of password sharing to the sophisticated, although often misunderstood, architectures of OAuth 1.0, OAuth 2.0, and OIDC. By illustrating the core components, flows, and potential vulnerabilities through engaging analogies, Wratten and Cornall equip developers and security professionals with a clearer understanding of how these protocols function and, crucially, how to implement them securely. The talk underscores the importance of proper implementation to prevent common attacks, emphasizing that a robust understanding of these standards is not merely a best practice but a fundamental requirement for modern application security.

The relevance of this discussion cannot be overstated. OAuth and OIDC underpin countless integrations across the internet, from social logins to third-party application access. Misconfigurations or incomplete understanding of these protocols can lead to significant security vulnerabilities, compromising user data and trust. Wratten and Cornall's clear exposition serves as an invaluable resource, guiding attendees through the intricate dance of tokens, redirects, and back-channel communications, ultimately empowering them to build more secure and resilient applications.

Background

▶ Watch: The insecure 'password sharing' era (2:00)

Before the advent of sophisticated authorization protocols, the primary method for one application to access a user's data on another platform was through password sharing. This era, as described by the speakers, presented a multitude of severe security and usability challenges. If a user, such as "Puss and Boots," wanted their note-taking app "Notion" to access documents stored in "Google Drive," they would directly provide Notion with their Google Drive password. This practice immediately introduced several critical vulnerabilities.

Firstly, giving Notion the Google Drive password granted it unfettered access to the user's entire account. Notion could not only read documents but also edit, delete, or even change the user's password, effectively allowing the third-party application to impersonate the user completely. This lack of granular control meant users had no way to limit the scope of access. Secondly, if a user wished to revoke Notion's access, they would have to manually change their Google Drive password, a cumbersome and often overlooked process. Thirdly, and perhaps most critically, Notion would need to store the user's password, likely in plain text or a weakly encrypted format, making it a prime target for attackers. A breach of Notion's systems could then compromise all connected Google Drive accounts, leading to widespread data theft.

Recognizing these inherent flaws, the need for a more secure and controlled method of delegated authorization became evident, leading to the development of OAuth. The first iteration, OAuth 1.0, emerged as a significant improvement, introducing the concept of access tokens. Instead of sharing passwords, users could grant specific, limited permissions to applications. For instance, Notion could be granted permission only to "read" Google Drive files, not to delete them or change account settings. This principle of least privilege was a revolutionary step. OAuth 1.0 also introduced a mechanism for applications to obtain these tokens without ever seeing the user's password, typically involving redirects and cryptographic signing to ensure authenticity. Although OAuth 1.0 is now largely deprecated, its foundational concepts, such as access tokens and the segregation of authorization from authentication, remain central to its successor, OAuth 2.0. The speakers highlight that understanding OAuth 1.0 provides a crucial stepping stone to grasping the more complex OAuth 2.0 framework, as many core ideas persist.

Key Findings

▶ Watch: Why the convoluted token exchange step? (7:30)

The talk distills several critical insights into the architecture and security of modern authorization and authentication flows. A primary finding is the distinction between OAuth and OpenID Connect (OIDC), clarifying that OAuth is fundamentally an authorization framework—designed for granting applications permission to access resources on a user's behalf—while OIDC is an identity layer built on top of OAuth 2.0, specifically for authentication (verifying a user's identity). This differentiation is crucial for proper implementation and understanding of their respective security models.

Another key finding emphasizes that OAuth 2.0 is a framework, not a rigid protocol. This flexibility allows it to adapt to various client types (web, mobile, desktop) but also introduces complexity, as many implementation details are left to the developer. This flexibility, while powerful, necessitates a deep understanding of its security implications, particularly when selecting and implementing specific flows like the Authorization Code Flow.

The most critical security takeaway highlighted by the speakers is the absolute necessity of state validation. The state parameter, a seemingly minor component, plays a vital role in mitigating Cross-Site Request Forgery (CSRF) attacks during the OAuth flow. Failing to validate this parameter can lead to severe vulnerabilities, allowing attackers to link a victim's account to the attacker's third-party service, as vividly demonstrated in the talk's conceptual attack scenario. This single point is repeatedly stressed as "the one thing you get out of this talk."

Finally, the talk underscores the importance of back-channel communication for the secure exchange of tokens. The token exchange step, where an authorization code is swapped for an access token, must occur directly between the client application's server and the authorization server. This server-to-server communication, hidden from the user's browser, prevents malicious actors from intercepting sensitive access tokens, a crucial security feature distinguishing modern OAuth from less secure alternatives.

Technical Deep Dive

▶ Watch: Crucial state validation in OAuth 2.0 (12:00)

The talk meticulously dissects the technical mechanics of both OAuth 1.0 and OAuth 2.0, culminating in an explanation of OpenID Connect. The progression from one standard to the next highlights the continuous refinement of security and usability.

OAuth 1.0: The Genesis of Delegated Authorization

OAuth 1.0, while deprecated, introduced foundational concepts. The process begins with client registration, where "Notion" registers with "Google," obtaining a unique Client ID and a Client Secret. These credentials allow Notion and Google to verify each other's identity in future communications.

When "Puss and Boots" initiates an integration, Notion first requests an unauthorized request token from Google, sending its Client ID. Google responds with this token. Notion then redirects Puss and Boots' browser to Google's authentication page. Here, Puss and Boots logs in and is presented with a consent screen, detailing the permissions Notion is requesting (e.g., "See and download all of your Google Drive files"). If accepted, Puss and Boots is redirected back to Notion, but crucially, the request token is now marked as authorized.

The pivotal step for security in OAuth 1.0 is the token exchange. Notion, now possessing the authorized request token, performs a back-channel communication (server-to-server, unseen by the user's browser) with Google. It sends the authorized request token, along with its Client ID and Client Secret, to Google. Google verifies these credentials and, if legitimate, issues a magical access token. This access token, with its granular permissions, is then used by Notion to interact with Google Drive on Puss and Boots' behalf. The reason for this convoluted exchange, as explained, is to prevent an attacker who might compromise Puss and Boots' browser from directly stealing the valuable access token; they can only steal the less powerful request token, which Google will refuse to exchange without the client secret.

OAuth 2.0: A Flexible Framework

OAuth 2.0, a framework rather than a strict protocol, introduces new terminology but retains the core concepts of token exchange and back-channel communication. The key players are the Resource Owner (Puss and Boots), the Client (Notion), the Authorization Server (Google's authentication service), and the Resource Server (Google Drive).

The most common flow discussed is the Authorization Code Flow.

  1. Initiation: Puss and Boots wants Notion to access Google Drive. Notion, having pre-registered with Google and obtained a Client ID and Client Secret, constructs a redirect URL.
  2. Redirect to Authorization Server: Puss and Boots' browser is redirected to Google's Authorization Server with several URL parameters:
  • response_type=code: Indicating the Authorization Code flow.
  • client_id: Notion's identifier.
  • scope: The requested permissions (e.g., https://www.googleapis.com/auth/drive.readonly, email).
  • state: A randomly generated, unique string. Crucially, Notion stores this state value in a cookie on Puss and Boots' browser before the redirect.
  1. User Authentication and Consent: Puss and Boots logs into Google (if not already) and is presented with a consent screen corresponding to the requested scope values.
  2. Redirect Back with Authorization Code: If Puss and Boots accepts, Google redirects the browser back to Notion's pre-registered redirect URI. This URL now includes an authorization code and the original state value.
  3. State Validation: Upon receiving this redirect, Notion performs a critical security check: it compares the state value received in the URL with the state value stored in the cookie. If they do not match, the process is aborted. This prevents CSRF attacks.
  4. Token Exchange (Back-Channel): If state validation passes, Notion initiates a back-channel (server-to-server) request to Google's Authorization Server. It sends the authorization code, its client_id, and its client_secret.
  5. Access Token Issuance: Google verifies these credentials. If valid, it responds with an access token (e.g., a bearer token), the granted scope, and its expiry time.
  6. Resource Access: Notion now uses this access token to make authenticated requests to Google Drive (the Resource Server) to fetch Puss and Boots' documents.

OpenID Connect (OIDC): Adding Identity

OpenID Connect builds directly on top of OAuth 2.0, adding an identity layer for authentication. The flow is identical to OAuth 2.0's Authorization Code flow, with one key addition during the token exchange step.

When Notion exchanges the authorization code for an access token, Google's Authorization Server, if OIDC is requested (typically by including openid in the scope), also returns an ID Token alongside the access token.

The ID Token is a JWT (JSON Web Token). A JWT is a compact, URL-safe means of representing claims to be transferred between two parties. It consists of three parts: a header, a payload, and a signature.

  • Payload: Contains claims about the authentication event and the user, such as email, name, sub (subject identifier), and iss (issuer). For example, it might contain Puss and Boots' email address and name from their Google account.
  • Signature: Cryptographically verifies the token's integrity, ensuring it hasn't been tampered with and that it originated from the legitimate issuer (Google).

Notion can then verify the signature of the ID Token and extract the user's information from its payload. This information can be used to create or log in Puss and Boots' account on Notion's platform, facilitating social logins without Notion ever needing to manage Puss and Boots' password. OIDC thus provides a standardized, secure way to delegate user authentication, leveraging the robust authorization capabilities of OAuth 2.0.

Demo / Proof of Concept

▶ Watch: Demonstrating a lack of state validation attack (13:30)

While the talk did not feature a live coding demo, it presented a crucial conceptual "what could go wrong" scenario to highlight the severe implications of neglecting state validation in the OAuth 2.0 Authorization Code flow. This scenario effectively functions as a proof of concept for a CSRF-like attack against the OAuth process.

The scenario unfolds as follows:

  1. Vulnerable Setup: The Notion application, in this hypothetical case, is configured without storing the state parameter in a cookie during the initial redirect to Google's Authorization Server, and critically, it performs no validation of the state parameter when the user is redirected back.
  2. Attacker (Fairy Godmother) Initiates Flow: The attacker, Fairy Godmother, initiates the OAuth flow with Notion. She is redirected to Google, signs into her own Google account, and accepts the consent screen for Notion to access her Google Drive.
  3. Authorization Code Interception: Before Google redirects Fairy Godmother back to Notion, she intercepts the redirect URL using a tool like a web proxy. This URL contains an authorization code that is valid for her Google account, along with a state parameter (which Notion will ignorantly accept).
  4. Malicious Link Crafting: Fairy Godmother then crafts a malicious link containing her valid authorization code and state parameter.
  5. Victim (Puss and Boots) Interaction: Fairy Godmother sends this malicious link to Puss and Boots via email, DM, or any other social engineering vector. If Puss and Boots clicks this link, their browser is directed to Notion with Fairy Godmother's authorization code.
  6. Vulnerable Client Action: Because Notion does not validate the state parameter (or any other appropriate checks to ensure the code belongs to the current user's session), it accepts Fairy Godmother's authorization code as if it originated from Puss and Boots' session. Notion proceeds to exchange this code for an access token.
  7. Account Hijacking/Linking: The result is that Puss and Boots' Notion account is now connected to Fairy Godmother's Google Drive account. Puss and Boots, expecting to see their own documents, would instead see Fairy Godmother's files. The implications extend beyond just files; if Notion offers access to more sensitive data (e.g., financial bills, confidential notes), this vulnerability could expose Puss and Boots to significant privacy breaches or even allow Fairy Godmother to manipulate data through Puss and Boots' Notion interface.

This conceptual demonstration powerfully illustrates why state validation is not an optional security feature but a fundamental requirement for correctly implementing the OAuth 2.0 Authorization Code flow. Without it, the integrity of the user's session and the security of their delegated access are severely compromised.

Defensive Implications

▶ Watch: Key takeaways and future considerations (18:30)

The detailed exploration of OAuth and OpenID Connect reveals several critical defensive implications for developers, application security engineers, and organizations. Implementing these protocols correctly is not trivial, but adherence to best practices can significantly mitigate risks.

  1. Always Validate the state Parameter: This is the paramount defensive measure highlighted in the talk. For any OAuth 2.0 Authorization Code flow, the state parameter generated by the client must be stored securely (e.g., in a session cookie) before redirecting the user to the Authorization Server. Upon redirection back, the state parameter received in the URL must be compared with the stored value. A mismatch indicates a potential CSRF attack, and the flow must be aborted. This simple yet crucial step prevents attackers from linking their accounts to a victim's session.
  1. Understand OAuth vs. OIDC: Defenders must clearly differentiate between authorization (OAuth) and authentication (OIDC). OAuth grants permission to access resources, while OIDC verifies identity. Misunderstanding this distinction can lead to misconfigurations where authentication logic is built on top of an authorization-only flow, potentially exposing identity claims or failing to properly verify user sessions.
  1. Secure Back-Channel Communications: The token exchange (swapping an authorization code for an access token) must always occur over a secure back-channel (server-to-server) connection, protected by TLS. This prevents the sensitive access token from being exposed in the user's browser, where it could be intercepted by malicious scripts or proxies. The client_secret should never be exposed to the client-side (e.g., in a browser or mobile app directly).
  1. Implement Least Privilege with Scopes: When requesting scope values, applications should always adhere to the principle of least privilege. Request only the permissions absolutely necessary for the application's functionality. Over-requesting scopes increases the attack surface, as a compromised access token would grant broader access than required. Users are also more likely to consent to minimal, clearly defined permissions.
  1. Protect Client Secrets: For confidential clients (like web applications with a backend), the client_secret is a critical credential. It must be stored securely on the application server and never committed to version control or exposed in client-side code. Compromise of a client_secret can allow an attacker to impersonate the application and potentially obtain access tokens.
  1. Refer to Official Documentation and Threat Models: The speakers explicitly recommend consulting the OAuth 2.0 Threat Model and Security Considerations (RFC 6819) document. This RFC outlines common attack vectors and provides comprehensive mitigation strategies. Relying on well-established security guidelines rather than ad-hoc implementations is crucial for avoiding subtle vulnerabilities inherent in such complex protocols.
  1. Consider Different Client Types: While the Authorization Code flow is robust for traditional web applications, other flows (like PKCE for public clients, not covered in depth but mentioned) are necessary for mobile or single-page applications where a client_secret cannot be kept confidential. Defenders must choose the appropriate flow for their client type and implement its specific security mechanisms.
  1. Regularly Review Implementations: Given the complexity and evolving nature of web security, regular security audits and code reviews of OAuth and OIDC implementations are essential. This includes checking for correct state validation, proper scope usage, secure storage of credentials, and adherence to the latest security recommendations.

By diligently applying these defensive strategies, organizations can significantly strengthen the security posture of their applications that rely on delegated authorization and identity verification, protecting user data and maintaining trust.

Key Takeaways

  • OAuth is for Authorization, OIDC is for Identity: Clearly distinguish between OAuth 2.0, an authorization framework for granting access to resources, and OpenID Connect, an authentication layer built on OAuth 2.0 for verifying user identity via ID Tokens.
  • Always Validate the state Parameter: The state parameter is a critical anti-CSRF mechanism in OAuth 2.0 Authorization Code Flow. Failure to validate the state received in the redirect URL against a securely stored, session-specific value can lead to severe account linking vulnerabilities.
  • Token Exchange via Back-Channel is Crucial: The exchange of an authorization code for an access token must occur directly between the client's backend server and the authorization server over a secure, server-to-server (back-channel) connection. This prevents sensitive access tokens from being exposed in the user's browser.
  • OAuth 2.0 is a Flexible Framework with Security Considerations: OAuth 2.0 offers flexibility for various application types but requires careful implementation. Developers must understand the specific security implications and best practices for their chosen flow, often referring to comprehensive threat models like RFC 6819.
  • Embrace Least Privilege for Scopes: Request only the minimum necessary permissions (scopes) from users. Over-requesting access increases the attack surface and can deter user consent.
  • Leverage Official Documentation: The OAuth 2.0 Threat Model and Security Considerations (RFC 6819) is an invaluable resource for understanding attack vectors and implementing robust mitigations.

About the Speaker(s)

Laura Wratten and Angus Cornall are Application Security Engineers at Canva, a global visual communication platform. This talk marked their debut as conference speakers, a fact highlighted by the conference organizers. They are described as "best friends," bringing an engaging and collaborative dynamic to their presentation. Their expertise lies in securing complex web applications, and their ability to simplify intricate security protocols like OAuth and OpenID Connect demonstrates their deep understanding and commitment to educating the wider security community.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

Competent OAuth 101 that hits all the standard beats—state validation, back-channel token exchange, the OAuth-vs-OIDC distinction. Good for someone who's never implemented an OAuth flow, but offers nothing practitioners haven't seen in a hundred blog posts, RFC summaries, or Aaron Parecki tutorials.

Heather Calloway (CISO) — SOLID

Competent primer on OAuth/OIDC fundamentals with clear emphasis on state validation as the critical defensive control. Useful for teams onboarding junior engineers or reviewing third-party integration security, but offers no new ground for practitioners already implementing these flows.

→ Top-rated talks at purplecon 2024

All talks from purplecon 2024