Created
November 22, 2016 01:58
-
-
Save zer0tonin/b602ebfa6fcf3aba62f88622168f8c75 to your computer and use it in GitHub Desktop.
Simple XSS removal in Node JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>XSS Protector!</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<form method="post" action="result"> | |
<label for="input">Input : </label> | |
<input type="text" name="input"></input> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>XSS Protector!</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<p><%= input %></p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var app = express(); | |
var bodyParser = require("body-parser"); | |
var urlencodedParser = bodyParser.urlencoded({ extended: false }); | |
app.listen(8080,function(){ | |
console.log("Listening on port 8080"); | |
}); | |
app.get('/', function(req, res){ | |
res.sendFile(__dirname + "/index.html"); | |
}); | |
app.post('/result', urlencodedParser, function(req, res){ | |
var input = req.body.input.replace(/&/g,'').replace(/</g,'').replace(/>/g,''); | |
res.render(__dirname + "/result.ejs", {input: input}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment