Skip to content

Commit d03b433

Browse files
committed
add additional logging for CSRF errors, redirect to 404 for invalid embed path
1 parent 28c2bda commit d03b433

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

server/controllers/embed.controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import {
55
resolvePathsForElementsWithAttribute,
66
resolveScripts,
77
resolveStyles } from '../utils/previewGeneration';
8+
import { get404Sketch } from '../views/404Page';
89

910
export function serveProject(req, res) {
1011
Project.findById(req.params.project_id)
1112
.exec((err, project) => {
13+
if (err || !project) {
14+
return get404Sketch(html => res.send(html));
15+
}
1216
// TODO this does not parse html
1317
const files = project.files;
1418
const htmlFile = files.find(file => file.name.match(/\.html$/i)).content;

server/server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ app.get('*', (req, res) => {
131131
res.type('txt').send('Not found.');
132132
});
133133

134+
// error handler
135+
app.use((err, req, res, next) => {
136+
if (err.code !== 'EBADCSRFTOKEN') return next(err);
137+
138+
console.error('Invalid CSRF token for: ' + req.url);
139+
return next(err);
140+
});
141+
134142
// start app
135143
app.listen(serverConfig.port, (error) => {
136144
if (!error) {

0 commit comments

Comments
 (0)