
// oauth_server.js - OAuth2 provider issuing tokens in fragment
const express = require('express');
const app = express();
app.get('/authorize', (req, res) => {
const redirectUri = req.query.redirect_uri;
const state = req.query.state || '';
// Simulate user approval: redirect with access token in fragment
const token = 'secret_access_token';
res.redirect(`${redirectUri}#access_token=${token}&state=${state}`);
});
app.listen(3000, () => console.log('OAuth server on :3000'));
An OAuth2 provider implements the implicit grant flow without validating the redirect_uri against a whitelist. An attacker can supply a malicious URI and, after the user authenticates, the access token is leaked via the URL fragment to the attacker’s page.
redirect_uri exactly matches a pre-registered value, allowing redirection to an attacker-controlled domain.npm install express
node oauth_server.js
python exploit_fragment_hijack.py