Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Remove CSRF for now
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler committed May 15, 2019
1 parent c038a22 commit fd0b791
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 36 deletions.
13 changes: 0 additions & 13 deletions lib/formHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function parseForm(req) {
return new Promise((resolve, reject) => {
const formFields = {};
const uniqueName = uuidv4();
let csrfChecked = false;

form.parse(req)
.on('fileBegin', (name, file) => {
Expand All @@ -30,14 +29,6 @@ function parseForm(req) {
})
.on('field', (name, field) => {
debug('INCOMING_REQUEST_FIELD', name, field);
if (name === '_csrf') {
if (req.session.csrf !== field) {
return reject(new Error('INVALID_CSRF'));
}

csrfChecked = true;
return;
}

if (name === 'github' && field && !field.startsWith('@')) {
field = `@${field}`;
Expand Down Expand Up @@ -65,10 +56,6 @@ function parseForm(req) {
reject(err);
})
.on('end', () => {
if (!csrfChecked) {
return reject(new Error('NO_CSRF_CHECK_ABORTING'));
}

const allFieldsValidated = validateFields(formFields);
if (!allFieldsValidated) {
return reject(new Error('VALIDATION_FAILED'));
Expand Down
18 changes: 0 additions & 18 deletions middleware.js

This file was deleted.

5 changes: 1 addition & 4 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

const debug = require('debug')('mozilla-fenix-campaign:routes');
const express = require('express');
const middleware = require('../middleware');
const formHandling = require('../lib/formHandling');
const githubBackend = require('../lib/githubBackend');

const router = express.Router();

const { OWNER, REPO } = process.env;
const { csrfProtection } = middleware;

router.get('/', csrfProtection, async (req, res) => {
router.get('/', async (req, res) => {
debug('INCOMING_REQUEST_INDEX');
const issue = `https://github.com/${OWNER}/${REPO}/issues/${req.query.issue}`
res.render('index', {
success: /true/.test(req.query.success),
submitted: /true/.test(req.query.submitted),
issue,
csrf: req.session.csrf,
});
});

Expand Down
1 change: 0 additions & 1 deletion views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ block content
div(class="input-group")
label(for="github") Your GitHub account name if you have one<br><span class="field-note">(this will appear in the public GitHub issue)</span>
input(id="github", type="text", name="github")
input(id="csrf", type="hidden", name="_csrf", value=csrf)
button(type="submit") Create Issue

footer
Expand Down

0 comments on commit fd0b791

Please sign in to comment.