Skip to content

Instantly share code, notes, and snippets.

@zer0tonin
Created November 22, 2016 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zer0tonin/b602ebfa6fcf3aba62f88622168f8c75 to your computer and use it in GitHub Desktop.
Save zer0tonin/b602ebfa6fcf3aba62f88622168f8c75 to your computer and use it in GitHub Desktop.
Simple XSS removal in Node JS
<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>
<html>
<head>
<title>XSS Protector!</title>
<meta charset="utf-8">
</head>
<body>
<p><%= input %></p>
</body>
</html>
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