Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This changelog lists changes to operations infrastructure, i.e., code changes to
- reduce `central-backend` worker count for some systems with <1GB RAM (getodk/central#2306)
- rename `secrets.dockerfile` -> `enketo-secrets.dockerfile` (getodk/central#2303)
- rename `files/enketo/generate-secrets.sh` -> `files/enketo-secrets/generate-secrets.sh` (getodk/central#2303)
- allow embeddeding of public-access forms in iframes (getodk/central#2321)

## 2026.3.0

Expand Down
9 changes: 7 additions & 2 deletions files/nginx/odk.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ map $arg_st $redirect_single_prefix {
default "/new${is_args}${args}${qp_deliminator}single=true";
}

map $arg_st $formwrapper_frame_ancestors {
~.+ "*";
default "'self'";
}

# Note: using $request_uri here remains safe while percent-encodings are not
# normalised in frontend URLs. Tracked at https://github.com/getodk/central/issues/1532
map $request_uri $spa_name {
Expand All @@ -102,7 +107,7 @@ map $spa_name $spa_csp {
# Use 'none' per directive instead of falling back to default-src to make CSP violation reports more specific

form-wrapper
"default-src 'report-sample' 'none'; connect-src 'self' https:; font-src 'self' data:; form-action 'self'; frame-ancestors 'self'; frame-src 'self' https://getodk.github.io/central/; img-src blob: data: https:; manifest-src 'self'; media-src blob:; object-src 'none'; script-src 'report-sample' 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; worker-src 'report-sample' blob: data:; report-uri /csp-report";
"default-src 'report-sample' 'none'; connect-src 'self' https:; font-src 'self' data:; form-action 'self'; frame-ancestors $formwrapper_frame_ancestors; frame-src 'self' https://getodk.github.io/central/; img-src blob: data: https:; manifest-src 'self'; media-src blob:; object-src 'none'; script-src 'report-sample' 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; worker-src 'report-sample' blob: data:; report-uri /csp-report";

default
"default-src 'report-sample' 'none'; connect-src 'self' ${SENTRY_DSN_FRONTEND_ROOT} https://translate.google.com https://translate.googleapis.com; font-src 'self'; form-action 'self'; frame-ancestors 'none'; frame-src 'self' https://getodk.github.io/central/; img-src data: https:; manifest-src 'self'; media-src 'none'; object-src 'none'; script-src 'report-sample' 'self'; style-src 'report-sample' 'self'; style-src-attr 'unsafe-inline'; worker-src 'report-sample' blob:; report-uri /csp-report";
Expand Down Expand Up @@ -227,7 +232,7 @@ server {
# central-frontend
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ $spa_html;
try_files $uri $uri/ "$spa_html$is_args$args";

add_header Content-Security-Policy "$spa_csp" always;

Expand Down
143 changes: 95 additions & 48 deletions test/nginx/src/mocha/nginx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,53 @@ const allowGoogleTranslate = ({ 'connect-src':connectSrc, 'img-src':imgSrc, ...o
return { ...others, 'connect-src':connectSrc, 'img-src':imgSrc };
};

const csp_formWrapperBase = {
block: allowGoogleTranslate({
'default-src': [
reportSample,
none,
],
'connect-src': [
self,
'https:',
],
'font-src': [
self,
'data:',
],
'form-action': self,
'frame-src': [
self, // web-forms wrapper pages also host /enketo-passthrough/ URLs via iframes
centralNotifications,
],
'img-src': [
'blob:',
'data:',
'https:',
],
'manifest-src': self,
'media-src': [
'blob:',
],
'object-src': none,
'script-src': [
reportSample,
self,
wasmUnsafeEval,
],
'style-src': [
self,
unsafeInline,
],
'worker-src': [
reportSample,
'blob:',
'data:',
],
'report-uri': '/csp-report',
}),
};

const contentSecurityPolicies = {
'backend-strict': {
block: {
Expand Down Expand Up @@ -166,52 +213,19 @@ const contentSecurityPolicies = {
'report-uri': '/csp-report',
}),
},
'form-wrapper': { // web-forms, and the enketo iframe owner
block: allowGoogleTranslate({
'default-src': [
reportSample,
none,
],
'connect-src': [
self,
'https:',
],
'font-src': [
self,
'data:',
],
'form-action': self,
'form-wrapper-general': { // web-forms, and the enketo iframe owner
...csp_formWrapperBase,
block: {
...csp_formWrapperBase.block,
'frame-ancestors': self,
'frame-src': [
self, // web-forms wrapper pages also host /enketo-passthrough/ URLs via iframes
centralNotifications,
],
'img-src': [
'blob:',
'data:',
'https:',
],
'manifest-src': self,
'media-src': [
'blob:',
],
'object-src': none,
'script-src': [
reportSample,
self,
wasmUnsafeEval,
],
'style-src': [
self,
unsafeInline,
],
'worker-src': [
reportSample,
'blob:',
'data:',
],
'report-uri': '/csp-report',
}),
},
},
'form-wrapper-publicAccess': { // web-forms, and the enketo iframe owner, specifically for public-access forms
...csp_formWrapperBase,
block: {
...csp_formWrapperBase.block,
'frame-ancestors': '*',
},
},
};

Expand Down Expand Up @@ -888,8 +902,16 @@ function standardTestSuite({ fetchHttp, fetchHttp6, apiFetch, apiFetch6, forward
'/projects/1/forms/some_xml_form_id/draft/preview/',
'/f/anything',
'/f/anything/',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?st=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?st=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',

// fake public-access form URLs
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?st=',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?st=',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?st=&y=z',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?st=&y=z',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?a=b?st=',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?a=b?st=',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?a=b?st=&y=z',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?a=b?st=&y=z',

// invalid submission ID - currently not checking for valid UUIDs
'/projects/1/forms/some_xml_form_id/submissions/any-old-nonsense/edit',
Expand All @@ -906,7 +928,32 @@ function standardTestSuite({ fetchHttp, fetchHttp6, apiFetch, apiFetch6, forward
// then
assert.equal(res.status, 200);
assert.equal(await res.text(), '<div id="form-wrapper"></div>\n');
assertSecurityHeaders(res, { csp:'form-wrapper' });
assertSecurityHeaders(res, { csp:'form-wrapper-general' });
});
});

[
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?st=1',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?st=1',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?st=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?st=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',

// fake public-access form URLs; ideally they would be detected correctly, but nginx's query param name matching is case-insensitive
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?ST=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?ST=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?St=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?St=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi?sT=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
'/f/SCUZtGUjC7fgL2O1AXqqG8YN8Jdkthi/?sT=vcm7tFeqEFR1Itrmjq50KEFSrK$osbXrtu',
].forEach(path => {
it(`should add specific Content Security Policy restrictions for public-access webforms path: ${path}`, async () => {
// when
const res = await apiFetch(path);

// then
assert.equal(res.status, 200);
assert.equal(await res.text(), '<div id="form-wrapper"></div>\n');
assertSecurityHeaders(res, { csp:'form-wrapper-publicAccess' });
});
});

Expand Down
10 changes: 9 additions & 1 deletion test/nginx/src/playwright/csp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ test.describe('frame rules', () => {
allowedFrameDestinations: [ /*none*/ ],
},
{
description: 'form-wrapper',
description: 'form-wrapper-general',
centralUrl: 'https://odk-nginx.example.test:9001/projects/1/forms/xml-form-id/submissions/new',
allowedFrameAncestors: [
'odkCentral',
Expand All @@ -157,6 +157,14 @@ test.describe('frame rules', () => {
'odkCentral',
],
},
{
description: 'form-wrapper-publicAccess',
centralUrl: 'https://odk-nginx.example.test:9001/projects/1/forms/xml-form-id/submissions/new?st=1',
allowedFrameAncestors: ALL_HOSTS,
allowedFrameDestinations: [
'odkCentral',
],
},
{
description: 'oidc-callback',
centralUrl: 'https://odk-nginx.example.test:9001/v1/oidc/callback',
Expand Down
Loading