-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from nyaomaru/deno-study-13
study: Content Security Policy
- Loading branch information
Showing
7 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"csp-report": { | ||
"document-uri": "http://localhost:8000/correctCSPwithReport", | ||
"referrer": "http://localhost:8000/", | ||
"violated-directive": "style-src-elem", | ||
"effective-directive": "style-src-elem", | ||
"original-policy": "default-src 'none'; style-src 'unsafe-inline' http://www.example.com; report-uri http://localhost:8000/reportHandler; script-src 'nonce-71d90af6c22f47f3b28399209fdd8dc5'; connect-src 'self'", | ||
"disposition": "report", | ||
"blocked-uri": "http://localhost:8000/example.css", | ||
"line-number": 1, | ||
"source-file": "http://localhost:8000/correctCSPwithReport", | ||
"status-code": 200, | ||
"script-sample": "" | ||
} | ||
} | ||
{ | ||
"csp-report": { | ||
"document-uri": "http://localhost:8000/correctCSPwithReport", | ||
"referrer": "http://localhost:8000/", | ||
"violated-directive": "style-src-elem", | ||
"effective-directive": "style-src-elem", | ||
"original-policy": "default-src 'none'; style-src 'unsafe-inline' http://www.example.com; report-uri http://localhost:8000/reportHandler; script-src 'nonce-71d90af6c22f47f3b28399209fdd8dc5'; connect-src 'self'", | ||
"disposition": "report", | ||
"blocked-uri": "http://localhost:8000/styles.css", | ||
"line-number": 1, | ||
"source-file": "http://localhost:8000/correctCSPwithReport", | ||
"status-code": 200, | ||
"script-sample": "" | ||
} | ||
} | ||
{ | ||
"csp-report": { | ||
"document-uri": "http://localhost:8000/correctCSPwithReport", | ||
"referrer": "http://localhost:8000/", | ||
"violated-directive": "img-src", | ||
"effective-directive": "img-src", | ||
"original-policy": "default-src 'none'; style-src 'unsafe-inline' http://www.example.com; report-uri http://localhost:8000/reportHandler; script-src 'nonce-71d90af6c22f47f3b28399209fdd8dc5'; connect-src 'self'", | ||
"disposition": "report", | ||
"blocked-uri": "http://localhost:8000/favicon.ico", | ||
"status-code": 200, | ||
"script-sample": "" | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { RouteConfig, RouteContext } from "$fresh/server.ts"; | ||
import { useCSP } from "$fresh/runtime.ts"; | ||
|
||
export default function Home(_req: Request, _ctx: RouteContext) { | ||
useCSP((csp) => { | ||
csp.reportOnly = true; | ||
if (!csp.directives.styleSrc) { | ||
csp.directives.styleSrc = []; | ||
} | ||
csp.directives.reportUri = "http://localhost:8000/reportHandler"; | ||
csp.directives.styleSrc.push("http://www.example.com"); | ||
}); | ||
return ( | ||
<> | ||
<h1>This page adheres to our configured CSP. Styles will be applied.</h1> | ||
<link rel="stylesheet" type="text/css" href="example.css" /> | ||
</> | ||
); | ||
} | ||
|
||
export const config: RouteConfig = { | ||
csp: true, | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { FreshContext } from "$fresh/server.ts"; | ||
|
||
export const handler = { | ||
async POST(req: Request, _ctx: FreshContext) { | ||
const body = await req.json(); | ||
const report = JSON.stringify(body, null, 2); | ||
|
||
await Deno.writeTextFile("./csp-reports.txt", report + "\n", { | ||
append: true, | ||
}); | ||
return new Response(null, { status: 200 }); | ||
}, | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
h1 { | ||
font-size: 25px; | ||
font-weight: normal; | ||
margin-top: 5px; | ||
margin-left: 25px; | ||
} |