Latest / CyberCode Academy / Course 2 - API Security Offence and Defense | Episode 3: OAuth Protocol: Standards, Authorization Flows, Attacks, and Real-World Case Study
Transcript
- 0:00Speaker 1: So if you've ever clicked the button that says log
- 0:01Speaker 1: in with Google or connect with Twitter, you've used one
- 0:05Speaker 1: of the most brilliant security shortcuts out there.
- 0:08Speaker 2: It really is. It feels like magic.
- 0:10Speaker 1: It does. A random app gets access to your data,
- 0:13Speaker 1: but you never have to type in your main password.
- 0:15Speaker 1: So how does that actually work? And more importantly, how
- 0:18Speaker 1: do attackers break it?
- 0:20Speaker 2: Well, that magic is the o ARTH protocol, and today
- 0:23Speaker 2: our mission is a deep dive into its architecture, the standards,
- 0:27Speaker 2: and well how attackers exploit tiny flaws to compromise accounts.
- 0:31Speaker 1: Okay, so before we get into the attacks, we had
- 0:33Speaker 1: to clear up some core ideas first.
- 0:35Speaker 2: Absolutely, the biggest one is the difference between authentication and authorization.
- 0:40Speaker 2: People mix them up all the time. Authentication is just
- 0:43Speaker 2: proving who you are. Think username and password. Oh, it
- 0:47Speaker 2: actually assumes you've already done that. It doesn't handle your login.
- 0:51Speaker 1: So it's not about identity. It's about power precisely.
- 0:54Speaker 2: O LOTH is all about authorization, defining what you can do.
- 0:58Speaker 2: It's the process of giving a third party app very specific,
- 1:02Speaker 2: limited power over your account.
- 1:04Speaker 1: And that's the little pop up window that says this
- 1:07Speaker 1: app wants to read your profile and post tweets.
- 1:09Speaker 2: That's it exactly. That's the scope being defined. So instead
- 1:12Speaker 2: of your master key, the app gets this special temporary key.
- 1:17Speaker 1: And that key is the access token.
- 1:19Speaker 2: The access token that's the prize. It's what the application
- 1:22Speaker 2: uses to prove it has your permission, and for an attacker,
- 1:26Speaker 2: getting their hands on that token is the end goal.
- 1:29Speaker 1: Okay, So to really get how the modern standard works,
- 1:32Speaker 1: we should probably touch on why the old ways failed.
- 1:35Speaker 1: I mean they used to just ask for.
- 1:36Speaker 2: Your passwords they did, or they relied on you know,
- 1:39Speaker 2: messy cookie sharing tricks. Oh youth really became the standard
- 1:43Speaker 2: that everyone Google, Facebook, all of them adopted. But before
- 1:46Speaker 2: we dig into the flows, we should probably run through
- 1:49Speaker 2: some key terms.
- 1:50Speaker 1: Let's do it. What are the essential pieces?
- 1:52Speaker 2: First up, you have the client ID and the consumer secret.
- 1:55Speaker 2: Think of this as the app's own username and password.
- 1:58Speaker 2: It's how the app identified itself to the service.
- 2:01Speaker 1: Okay, so the app has its own credentials, and we
- 2:03Speaker 1: mentioned the scope, which is what it's allowed to do.
- 2:06Speaker 1: What about the security bits right?
- 2:08Speaker 2: For that, The most important one to understand is the
- 2:11Speaker 2: state parameter. It's just a unique random string of text
- 2:15Speaker 2: that the application sends at the very start of the process.
- 2:18Speaker 1: The server has to send it back.
- 2:20Speaker 2: It has to send it back completely unchanged. It works
- 2:23Speaker 2: like a security seal on a package. Its main job
- 2:26Speaker 2: is to prevent a nasty attack called cross site request
- 2:29Speaker 2: forgery or CSRF. It proves the response you're getting is
- 2:33Speaker 2: for the request you actually made.
- 2:34Speaker 1: Got it okay? So that brings us to the history,
- 2:37Speaker 1: ohof one point zero A.
- 2:39Speaker 2: The legacy version right one point zero A was built
- 2:43Speaker 2: around this idea of as signed request. For every single communication,
- 2:47Speaker 2: the app had to cryptographically hash the entire request, often
- 2:51Speaker 2: using its secret key.
- 2:52Speaker 1: That sounds really complicated to get right.
- 2:54Speaker 2: It was incredibly complex. It couldn't fully rely on a
- 2:57Speaker 2: single secure channel, so it used all this complex math
- 3:00Speaker 2: verify every message. You had to worry about clocksink between servers.
- 3:03Speaker 2: It was just a massive headache for developers.
- 3:05Speaker 1: Which is where oh if two point zero comes in
- 3:07Speaker 1: and just simplifies everything it does.
- 3:09Speaker 2: It basically leans on the fact that we have SSLTLUS
- 3:12Speaker 2: now you know, secure web connections, so it dropped all
- 3:15Speaker 2: that mandatory per request signing.
- 3:17Speaker 1: What does it do instead?
- 3:19Speaker 2: It uses what's called the three lighted authorization code GRANT flow.
- 3:23Speaker 2: This is the one you see almost everywhere.
- 3:25Speaker 1: Okay, walk me through that. Why is it so much better?
- 3:28Speaker 2: So in two point zero, the client first asks for
- 3:31Speaker 2: a temporary, short lived thing called an authorization code, and
- 3:35Speaker 2: this kind critically is useless by itself, right. The client
- 3:39Speaker 2: then takes that code, and in a secret server deceaver communication,
- 3:43Speaker 2: it exchanges that code for the final access token.
- 3:46Speaker 1: Ah. So the really sensitive handoff never happens in the
- 3:49Speaker 1: user's browser. It's all in the.
- 3:51Speaker 2: Back end exactly. It's far more secure, and it gets
- 3:53Speaker 2: rid of all that messy cryptography for every single request.
- 3:57Speaker 2: Security moves from constant signing to one's cure exchange.
- 4:01Speaker 1: Brilliant. Okay, now let's talk about how to break it,
- 4:03Speaker 1: because stealing that access token is the name of the game,
- 4:05Speaker 1: and the.
- 4:06Speaker 2: First most common way is an authentication code leak via
- 4:09Speaker 2: the redirect uri.
- 4:10Speaker 1: The redirect URI that's the web addressed the server sends
- 4:13Speaker 1: you back to after you click approve, right, yep.
- 4:16Speaker 2: And if the OATH server isn't really strict about where
- 4:19Speaker 2: it sends that.
- 4:20Speaker 1: Code, then you've got a huge problem.
- 4:21Speaker 2: You've got a huge implementation flaw. An attacker can craft
- 4:25Speaker 2: a malicious link where they change that redirect URI to
- 4:29Speaker 2: point to their own server. If the main server doesn't
- 4:32Speaker 2: check it against a strict whitelist.
- 4:34Speaker 1: It just sends the code straight to the attacker.
- 4:36Speaker 2: Straight to the attacker server, and then the attacker uses
- 4:39Speaker 2: that code to log in as the victim. Game over.
- 4:43Speaker 1: So this isn't a flaw in the OO standard itself.
- 4:46Speaker 1: It's a developer messing up the implementation.
- 4:49Speaker 2: That's the core of almost every major OATH attack. It's
- 4:51Speaker 2: implementation error which brings us to the second big one,
- 4:57Speaker 2: a missing state parameter.
- 4:58Speaker 1: Right the security see what we talked about. If an
- 5:00Speaker 1: app forgets to include that, it opens the door for
- 5:03Speaker 1: a csr F attack.
- 5:04Speaker 2: Correct. But what's really interesting here is the goal is different.
- 5:08Speaker 2: It's not about stealing the victim's data right away. It's
- 5:10Speaker 2: about what we call account poisoning.
- 5:12Speaker 1: So the attacker's goal is to force the victim to
- 5:15Speaker 1: log in to the third party app, but using the
- 5:18Speaker 1: attacker's social account exactly. Wait, why would they want me
- 5:21Speaker 1: to log in as them? What's the point of that?
- 5:22Speaker 2: Because a lot of services let you link multiple social
- 5:26Speaker 2: accounts to one profile. Your Google, your Twitter, your Facebook,
- 5:29Speaker 2: all tied together. If an attacker can trick you into
- 5:32Speaker 2: linking their account to your profile.
- 5:34Speaker 1: They have a permanent back door. They can just log
- 5:36Speaker 1: in with their own credentials and take over my.
- 5:38Speaker 2: Account and control everything, account recovery, you name it.
- 5:41Speaker 1: Wow. Okay, so those are the basics. But what about
- 5:44Speaker 1: when developers do use the state parameter. Let's get into
- 5:48Speaker 1: the more advanced attacks.
- 5:49Speaker 2: This is where things get really clever. If the state
- 5:52Speaker 2: parameter is in use, a smart attacker starts looking for
- 5:55Speaker 2: a completely different bug, a cross site scripting or EXSS
- 6:00Speaker 2: vulnerability on the client's website.
- 6:02Speaker 1: An XSS flaw lets an attacker inject their own JavaScript
- 6:05Speaker 1: into the page. So what would their script do.
- 6:08Speaker 2: The script injects a hidden, invisible iframe. That iframe starts
- 6:12Speaker 2: the whole oath process. But, and this is the key part,
- 6:16Speaker 2: it intentionally uses a wrong state.
- 6:18Speaker 1: Parameter, so the log in will fail. Right. The server
- 6:21Speaker 1: will see the state doesn't match and block it.
- 6:24Speaker 2: It will, but the attacker's script doesn't care. If the
- 6:27Speaker 2: login completes, All it needs to do is read the
- 6:30Speaker 2: URL in that iframe right before it fails. The valid
- 6:33Speaker 2: authorization code is sitting right there in the address bar,
- 6:36Speaker 2: so they.
- 6:37Speaker 1: Snatch the code out of the URL just before the
- 6:40Speaker 1: CSRF protection kicks in and kills the process exactly.
- 6:43Speaker 2: They grab the code, send it back to their own server,
- 6:45Speaker 2: and the CSRF check never even mattered.
- 6:48Speaker 1: That is devious. What's next?
- 6:50Speaker 2: The next one targets a really discouraged but still present
- 6:53Speaker 2: feature called the implicit flow. This is where the app
- 6:57Speaker 2: asks for a response type token instead of code.
- 7:00Speaker 1: And what does that mean.
- 7:01Speaker 2: It means the final live, all powerful access token gets
- 7:05Speaker 2: delivered directly in the URL. It completely bypasses that secure
- 7:09Speaker 2: server to server exchange.
- 7:10Speaker 1: Oh that sounds dangerous.
- 7:12Speaker 2: It is. If you combine that with an EXSS vulnerability,
- 7:15Speaker 2: the attackers script can just pluck the live token right
- 7:18Speaker 2: out of the URL fragment, no exchange needed, instant account compromise.
- 7:23Speaker 2: This is why I mean providers should just disable implicit
- 7:26Speaker 2: flow unless there's a very very good reason not to.
- 7:30Speaker 1: These chains are fascinating in theory, but the real world
- 7:34Speaker 1: case studies really bring it home. Let's talk about that Uber.
- 7:37Speaker 2: Case, right. The researcher Jack chained three seemingly minor things together.
- 7:41Speaker 2: First was a low impact self EXSS, which meant a
- 7:44Speaker 2: user had to trigger it on their own.
- 7:46Speaker 1: Profile, so not very useful on its own, not at all.
- 7:49Speaker 2: Second, uber's partner site was missing CSRF protection, no state parameter,
- 7:54Speaker 2: And third, he found a clever way to force a
- 7:56Speaker 2: user to log out using a simple HTML image tag.
- 7:59Speaker 1: So how did he change those three little bugs into
- 8:01Speaker 1: something big?
- 8:02Speaker 2: It was a beautiful rapid fire sequence. The attacker's page
- 8:05Speaker 2: would first use the logout trick to silently log the
- 8:08Speaker 2: victim out of just the partner site. Then, because there
- 8:11Speaker 2: was no CSRF protection, it immediately forced the victim to
- 8:14Speaker 2: log back in using the hacker's own account, which.
- 8:16Speaker 1: Means the victims browser briefly loads the attacker's.
- 8:19Speaker 2: Profile page and that's all it needed. That temporary page
- 8:23Speaker 2: load triggered the self EXSS payload that was waiting on
- 8:26Speaker 2: the hacker's profile. The script ran in a split second,
- 8:29Speaker 2: stole whatever data it needed from the victim session, and
- 8:31Speaker 2: then immediately logged the victim back into their own account.
- 8:34Speaker 1: The user would barely even see a flicker on the screen.
- 8:37Speaker 2: They'd never know what happened. It was the perfect hidden transaction.
- 8:41Speaker 1: And the GitHub case was even more complex, right A
- 8:43Speaker 1: five bug chain.
- 8:44Speaker 2: Yeah, that research was incredible. It involved five separate small flaws.
- 8:50Speaker 2: A tiny redirect URI bypass, a token endpoint that didn't
- 8:55Speaker 2: double check that URI, an XSS flaw in the GitHub
- 8:58Speaker 2: gist app, the fact that was a pre approved app
- 9:01Speaker 2: on every account with huge permissions. In the last piece,
- 9:04Speaker 2: a token leakage issue where the access token was being
- 9:07Speaker 2: stored in a cookie in a way that the XSS
- 9:09Speaker 2: script could read it.
- 9:11Speaker 1: So he used the EXSS in gist to kick the
- 9:13Speaker 1: whole thing off, knowing that the token it generated would
- 9:16Speaker 1: be powerful and that the endpoint wouldn't check where the
- 9:19Speaker 1: request came from.
- 9:20Speaker 2: He connected all five dots. The URI bypass started the flow,
- 9:24Speaker 2: the EXSS let him control the result, and the leaky
- 9:27Speaker 2: cookie gave him the final access token, full control, private code, everything,
- 9:32Speaker 2: just from five minor bugs.
- 9:34Speaker 1: That's the perfect takeaway. So for everyone listening, developers security pros,
- 9:39Speaker 1: let's distill this down. What is the single most critical
- 9:42Speaker 1: thing a developer has to do to secure their ooth flow.
- 9:45Speaker 2: It's two things, really, but they're absolutely non negotiable. One
- 9:48Speaker 2: always use the state parameter for CSRF protection always, and
- 9:52Speaker 2: two strictly validate the redirection against an approved whitelist no exception.
- 9:57Speaker 1: So en summary, use ss ltls, always use state disable
- 10:02Speaker 1: implicit flow if you can and be absolutely ruthless about
- 10:05Speaker 1: validating your redres. But the big lesson here seems to
- 10:08Speaker 1: be that you have to fix your other bugs too
- 10:09Speaker 1: you do.
- 10:10Speaker 2: As we saw, XSS is often the launch pad. A
- 10:13Speaker 2: simple XSS bug can become the key to a complete
- 10:16Speaker 2: ooth compromise, and that.
- 10:17Speaker 1: Really leaves us with a final kind of unsettling thought.
- 10:20Speaker 1: The real danger in these huge, complex systems isn't some
- 10:23Speaker 1: single catastrophic flaw in the protocol itself. It's the compounding
- 10:27Speaker 1: effect of all these little implementation mistakes.
- 10:30Speaker 2: So the question to think about is how many minor
- 10:33Speaker 2: bugs are just sitting there in the systems you use
- 10:36Speaker 2: every single day, waiting for someone clever enough to connect
- 10:39Speaker 2: the dots