Skip to content

Commit

Permalink
Merge pull request #563 from SaekiTominaga/reporting-api-v1
Browse files Browse the repository at this point in the history
Reporting API v1 対応(Reporting-Endpoints ヘッダー)
  • Loading branch information
SaekiTominaga authored Aug 26, 2024
2 parents 59195b1 + d7f3733 commit e86e403
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion configure/schema/express.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"header": {
"type": "object",
"title": "レスポンスヘッダー",
"required": ["hsts", "csp", "csp_html", "cspro_html"],
"required": ["hsts", "csp", "csp_html", "cspro_html", "reporting_endpoints"],
"properties": {
"hsts": {
"type": "string",
Expand All @@ -52,6 +52,14 @@
"cspro_html": {
"type": "string",
"title": "Content-Security-Policy-Report-Only (HTML)"
},
"reporting_endpoints": {
"type": "object",
"title": "Reporting-Endpoints",
"additionalProperties": {
"type": "string",
"title": "エンドポイントの URL"
}
}
},
"additionalProperties": false
Expand Down
8 changes: 8 additions & 0 deletions express/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ app.use(
/* CSP */
res.setHeader('Content-Security-Policy', config.response.header.csp);

/* Report */
res.setHeader(
'Reporting-Endpoints',
Object.entries(config.response.header.reporting_endpoints)
.map((endpoint) => `${endpoint.at(0) ?? ''}="${endpoint.at(1) ?? ''}"`)
.join(','),
);

/* MIME スニッフィング抑止 */
res.setHeader('X-Content-Type-Options', 'nosniff');

Expand Down

0 comments on commit e86e403

Please sign in to comment.