Last active
August 29, 2015 14:27
-
-
Save adunkman/ff81af4116ac1adfd15c to your computer and use it in GitHub Desktop.
Simple proof-of-concept for Content-Security-Policy in report-only mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require("express")(); | |
// JSON parse the body of requests with `application/csp-report` content type. | |
app.use(require("body-parser").json({ | |
type: "application/csp-report" | |
})); | |
// Page with CSP header (in report-only mode). | |
app.get("/", function (req, res) { | |
res.setHeader("Content-Security-Policy-Report-Only", [ | |
"default-src 'self' *.harvestapp.com", | |
"report-uri /csp-report-endpoint" | |
].join("; ")); | |
res.end("hello there"); | |
}); | |
// Receiver of CSP reports (sent by browser automatically). | |
app.post("/csp-report-endpoint", function (req, res) { | |
console.log(req.body); | |
res.end(); | |
}); | |
// Start server. | |
app.listen(process.env.PORT || 3000, function () { | |
console.log("listening", this.address()); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "csp-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"body-parser": "^1.13.3", | |
"express": "^4.13.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment