Add tests for CSRF and DNS rebind

Problem: We had these problems in the past and we can't have them again.
Solution: Tests make it really easy to double-check that we remain immune.
This commit is contained in:
Christian Bundy 2020-04-10 12:33:22 -07:00
parent 2968f7d80a
commit 627e1b3c76
2 changed files with 28 additions and 5 deletions

View File

@ -3,8 +3,9 @@
"language": "en", "language": "en",
"words": [ "words": [
"AGPL", "AGPL",
"EACCESS",
"Argyris", "Argyris",
"CSRF",
"EACCESS",
"Hintjens", "Hintjens",
"Kata", "Kata",
"LGPL", "LGPL",
@ -46,8 +47,8 @@
"shortname", "shortname",
"socio", "socio",
"ssbc", "ssbc",
"summerfruit",
"sulphurpool", "sulphurpool",
"summerfruit",
"systemctl", "systemctl",
"systemd", "systemd",
"unfollow", "unfollow",

View File

@ -28,13 +28,35 @@ const paths = [
tap.setTimeout(0); tap.setTimeout(0);
tap.test("DNS rebind attack fails", (t) => {
t.plan(1);
supertest(app)
.get("/inbox")
.set("Host", "example.com")
.expect(400)
.end(t.error);
});
tap.test("CSRF attack should fail with no referer", (t) => {
t.plan(1);
supertest(app).post("/conn/settings/stop").expect(400).end(t.error);
});
tap.test("CSRF attack should fail with wrong referer", (t) => {
t.plan(1);
supertest(app)
.post("/conn/settings/stop")
.set("Host", "example.com")
.expect(400)
.end(t.error);
});
paths.forEach((path) => { paths.forEach((path) => {
tap.test(path, (t) => { tap.test(path, (t) => {
t.plan(1); t.plan(1);
supertest supertest(app)
.agent(app)
.host("localhost") // supertest workaround
.get(path) .get(path)
.set("Host", "localhost")
.expect(200) .expect(200)
.end((err) => { .end((err) => {
console.log(path); console.log(path);