Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion files/nginx/odk.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ server {
try_files $uri $uri/ /index.html;

# Use 'none' per directive instead of falling back to default-src to make CSP violation reports more specific
add_header Content-Security-Policy-Report-Only "default-src 'none'; connect-src 'self' https://translate.google.com https://translate.googleapis.com; font-src 'self'; frame-src 'self' https://getodk.github.io/central/news.html; img-src * data: https://translate.google.com; manifest-src 'none'; media-src 'none'; object-src 'none'; script-src 'self'; style-src 'self'; style-src-attr 'unsafe-inline'; worker-src blob:; report-uri /csp-report";
add_header Content-Security-Policy-Report-Only "default-src 'none'; connect-src 'self' https://translate.google.com https://translate.googleapis.com; font-src 'self'; frame-src 'self' https://getodk.github.io/central/news.html; img-src data: https:; manifest-src 'none'; media-src 'none'; object-src 'none'; script-src 'self'; style-src 'self'; style-src-attr 'unsafe-inline'; worker-src blob:; report-uri /csp-report";

include /usr/share/odk/nginx/common-headers.conf;
}
Expand Down
25 changes: 15 additions & 10 deletions test/nginx/test-nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ const asArray = val => {
if (Array.isArray(val)) return val;
return [val];
};
const allowGoogleTranslate = ({ 'connect-src':connectSrc, 'img-src':imgSrc, ...others }) => ({
...others,
'connect-src': [
...asArray(connectSrc),
const allowGoogleTranslate = ({ 'connect-src':connectSrc, 'img-src':imgSrc, ...others }) => {
connectSrc = asArray(connectSrc);
if(!connectSrc.includes('https:')) connectSrc.push(
'https://translate.google.com',
'https://translate.googleapis.com',
],
'img-src': [
...asArray(imgSrc),
);

imgSrc = asArray(imgSrc);
if(!imgSrc.includes('https:')) imgSrc.push(
'https://translate.google.com',
],
});
);

return { ...others, 'connect-src':connectSrc, 'img-src':imgSrc };
};

const contentSecurityPolicies = {
'backend-unmodified': {
Expand All @@ -43,7 +45,10 @@ const contentSecurityPolicies = {
self,
'https://getodk.github.io/central/news.html',
],
'img-src': '* data:',
'img-src': [
'data:',
'https:',
],
'manifest-src': none,
'media-src': none,
'object-src': none,
Expand Down