Skip to content

Commit

Permalink
Content-Security-Policy (#4456)
Browse files Browse the repository at this point in the history
* とりあえず

* Remove v-animate-css

* Remove safe.js

* じしんがない

* Revert "Remove v-animate-css"

This reverts commit 3f78642.

* v-animate-cssがCDNを参照しないように

* wss

* Tune

* a
  • Loading branch information
mei23 committed Feb 8, 2023
1 parent 8e52e01 commit 0749ca3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Expand Up @@ -62,7 +62,7 @@ gulp.task('cleanall', gulp.parallel('clean', cb =>
gulp.task('build:client:script', () => {
// eslint-disable-next-line node/no-unpublished-require
const client = require('./built/meta.json');
return gulp.src(['./src/client/app/boot.js', './src/client/app/safe.js'])
return gulp.src(['./src/client/app/boot.js'])
.pipe(replace('VERSION', JSON.stringify(client.version)))
.pipe(replace('ENV', JSON.stringify(env)))
.pipe(replace('LANGS', JSON.stringify(Object.keys(locales))))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -154,7 +154,7 @@
"twemoji-parser": "git+https://github.com/mei23/twemoji-parser.git#15.0.1",
"typescript": "4.9.5",
"uuid": "9.0.0",
"v-animate-css": "0.0.5",
"v-animate-css": "0.0.6",
"v-debounce": "0.1.2",
"vue": "2.7.14",
"vue-color": "2.8.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/client/app/init.ts
Expand Up @@ -298,7 +298,7 @@ library.add(

Vue.use(Vuex);
Vue.use(VueRouter);
Vue.use(VAnimateCss);
Vue.use(VAnimateCss, { animateCSSPath: '/assets/animate.min.css?3.5.1' });
Vue.use(VModal);
Vue.use(VueHotkey);
Vue.use(VueSize);
Expand Down
13 changes: 0 additions & 13 deletions src/client/app/safe.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/client/assets/animate.min.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/client/assets/redoc.html
Expand Up @@ -5,7 +5,6 @@
<!-- needed for adaptive design -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">

<!--
ReDoc doesn't change outer page styles
Expand Down
21 changes: 19 additions & 2 deletions src/server/web/index.ts
Expand Up @@ -32,6 +32,19 @@ const env = process.env.NODE_ENV;
const staticAssets = `${__dirname}/../../../assets/`;
const client = `${__dirname}/../../client/`;

const csp
= `base-uri 'none'; `
+ `default-src 'none'; `
+ `script-src 'self'; `
+ `img-src 'self' https: data: blob:; `
+ `media-src 'self' https:; `
+ `style-src 'self' 'unsafe-inline'; `
+ `font-src 'self'; `
+ `frame-src 'self' https:; `
+ `manifest-src 'self'; `
+ `connect-src 'self' data: blob: ${config.wsUrl}; ` // wssを指定しないとSafariで動かない https://github.com/w3c/webappsec-csp/issues/7#issuecomment-1086257826
+ `frame-ancestors 'none'`;

// Init app
const app = new Koa();

Expand All @@ -50,6 +63,7 @@ app.use(favicon(`${client}/assets/favicon.ico`));
app.use(async (ctx, next) => {
// IFrameの中に入れられないようにする
ctx.set('X-Frame-Options', 'DENY');
ctx.set('Content-Security-Policy', csp);
await next();
});

Expand All @@ -67,7 +81,7 @@ router.get('/static-assets/*', async ctx => {
router.get('/assets/*', async ctx => {
await send(ctx as any, ctx.path, {
root: client,
maxage: ms('7 days'),
maxage: ctx.path === 'boot.js' ? ms('5m') : ms('7 days'),
});
});

Expand Down Expand Up @@ -190,6 +204,7 @@ router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
: [];

await ctx.render('user', {
version: config.version,
initialMeta: htmlescape(builded),
user,
me,
Expand Down Expand Up @@ -282,6 +297,7 @@ router.get('/notes/:note', async (ctx, next) => {
const height = 255;

await ctx.render('note', {
version: config.version,
initialMeta: htmlescape(builded),
note: _note,
summary: getNoteSummary(_note),
Expand All @@ -296,7 +312,6 @@ router.get('/notes/:note', async (ctx, next) => {

ctx.set('Cache-Control', 'public, max-age=180');


return;
});

Expand Down Expand Up @@ -358,6 +373,7 @@ router.get('/@:user/pages/:page', async ctx => {
const meta = await fetchMeta();
const builded = await buildMeta(meta, false);
await ctx.render('page', {
version: config.version,
initialMeta: htmlescape(builded),
page: _page,
instanceName: meta.name || 'Misskey',
Expand Down Expand Up @@ -438,6 +454,7 @@ router.get('*', async ctx => {
const noindex = ctx.path.match(/^[/](search|tags[/]|explore|featured)/);

await ctx.render('base', {
version: config.version,
initialMeta: htmlescape(builded),
img: meta.bannerUrl,
title: meta.name || 'Misskey',
Expand Down
5 changes: 1 addition & 4 deletions src/server/web/views/base.pug
Expand Up @@ -33,11 +33,8 @@ html

style
include ./../../../../built/client/assets/init.css
script
include ./../../../../built/client/assets/boot.js

script
include ./../../../../built/client/assets/safe.js
script(src=`/assets/boot.js?${version}`)

script(type='application/json' id='initial-meta').
!{initialMeta}
Expand Down

0 comments on commit 0749ca3

Please sign in to comment.