mirror of
https://github.com/docmost/docmost.git
synced 2026-07-27 11:04:39 +10:00
feat: iframe configuration
This commit is contained in:
@@ -12,6 +12,8 @@ import fastifyMultipart from '@fastify/multipart';
|
||||
import fastifyCookie from '@fastify/cookie';
|
||||
import fastifyIp from 'fastify-ip';
|
||||
import { InternalLogFilter } from './common/logger/internal-log-filter';
|
||||
import { EnvironmentService } from './integrations/environment/environment.service';
|
||||
import { resolveFrameHeader } from './common/helpers';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
@@ -50,6 +52,28 @@ async function bootstrap() {
|
||||
await app.register(fastifyMultipart);
|
||||
await app.register(fastifyCookie);
|
||||
|
||||
const environmentService = app.get(EnvironmentService);
|
||||
const frameHeader = resolveFrameHeader(
|
||||
environmentService.isIframeEmbedAllowed(),
|
||||
environmentService.getIframeAllowedOrigins(),
|
||||
);
|
||||
if (frameHeader) {
|
||||
// Skipped routes:
|
||||
// /api/files/ - attachment controller sets its own CSP we'd overwrite
|
||||
// /share/ 0 public share pages are safe to embed
|
||||
const frameHeaderSkippedPrefixes = ['/api/files/', '/share/'];
|
||||
app
|
||||
.getHttpAdapter()
|
||||
.getInstance()
|
||||
.addHook('onSend', (req, reply, payload, done) => {
|
||||
if (frameHeaderSkippedPrefixes.some((p) => req.url.startsWith(p))) {
|
||||
return done(null, payload);
|
||||
}
|
||||
reply.header(frameHeader.name, frameHeader.value);
|
||||
done(null, payload);
|
||||
});
|
||||
}
|
||||
|
||||
app
|
||||
.getHttpAdapter()
|
||||
.getInstance()
|
||||
|
||||
Reference in New Issue
Block a user