fix: let plugin frames use forms without letting them post anywhere

This commit is contained in:
Linus Rath
2026-10-14 06:19:12 +02:00
parent 5615704f5e
commit e9b2ef3258
3 changed files with 8 additions and 2 deletions
@@ -113,6 +113,8 @@ describe('plugin sandbox routes (GHSA-96cx-gx36-3g79)', () => {
}
// The router refetches the sandbox page itself, so its own origin stays.
expect(directives['connect-src']).toEqual(["'self'"]);
// Plugin frames may use forms (allow-forms) but not post them anywhere.
expect(directives['form-action']).toEqual(["'none'"]);
});
it('keeps https images and connections for the mail UI itself', async () => {
+3 -1
View File
@@ -161,7 +161,9 @@ export class SandboxInstance {
// `sandbox-ready` would never post).
const sandboxFlags = this.privileged || process.env.NODE_ENV === 'development'
? 'allow-scripts allow-same-origin'
: 'allow-scripts';
// allow-forms: plugin UIs can use <form> and get its submit event. The
// sandbox CSP sets form-action 'none', so a form can't post anywhere.
: 'allow-scripts allow-forms';
if (!this.privileged && process.env.NODE_ENV === 'development') warnDevSandboxOnce();
this.iframe.setAttribute('sandbox', sandboxFlags);
this.iframe.setAttribute('referrerpolicy', 'no-referrer');
+3 -1
View File
@@ -336,7 +336,9 @@ export async function proxy(request: NextRequest) {
frameSrc,
`object-src 'self' blob:`,
`base-uri 'self'`,
`form-action ${["'self'", ...wopiOrigins].join(" ")}`,
// Plugin frames may use <form> for its submit event (allow-forms), but a
// form must not post anywhere: that would be a way out past connect-src.
isSandboxPath ? `form-action 'none'` : `form-action ${["'self'", ...wopiOrigins].join(" ")}`,
`frame-ancestors ${frameAncestors}`,
`media-src 'self' blob:`,
].join("; ");