Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ and send out links to your friends.

var sys = require("sys");
var express = require("express");
var helmet = require("helmet");
var rateLimit = require("express-rate-limit");
var app = express.createServer();

// Configuration
Expand All @@ -15,6 +17,16 @@ app.use(express.bodyParser());
app.set("view engine", "ejs");
app.set("view options", { layout: false });

// Disable X-Powered-By header
app.use(helmet.hidePoweredBy());

// Rate limiting middleware
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
});
app.use(limiter);

// Routes
app.get("/", function(req, res) {
var xsrf = generateId();
Expand All @@ -30,6 +42,8 @@ app.post("/room", function(req, res) {
if (!xsrf || !matchXsrf || !(xsrf == matchXsrf))
return res.send({ error: "Unauthorized"}, 403);
var name = req.body.name;
if (typeof name !== 'string') // Type checking
return res.send({ error: "Invalid name type."}, 400);
res.header('content-type', 'application/json');
name = name.replace(/^\s+|\s+$/, "");
if (!name || name.length < 4 || name.replace(/^[\w\s]+$/, "") != "")
Expand Down
7 changes: 6 additions & 1 deletion public/static/js/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ Create = {
},

success: function(data) {
window.location.href = data.url;
var url = data.url;
if (url && url.startsWith('/')) { // Ensure the URL is relative
window.location.href = url;
} else {
alert("Invalid redirect URL");
}
},

error: function(data) {
Expand Down