fix(htaccess): serve .json and .ftl files statically instead of routing them to the front controller - #63947
Conversation
…ng them to the front controller The bundled pdf.js of files_pdfviewer loads its localization from apps/files_pdfviewer/js/pdfjs/web/locale/locale.json and apps/files_pdfviewer/js/pdfjs/web/locale/<lang>/viewer.ftl. With pretty URLs enabled, both extensions are missing from the static file exclusion of the generated front controller rule, so Apache passes the requests to index.php, which answers 404. pdf.js then fails to initialize and shows the alt text dialog instead of the document. Our nginx reference configuration serves both through try_files, and so does an Apache instance without pretty URLs, so this only brings the pretty URL case in line with the other two. To not widen what is reachable in the process, the package manager metadata that the nginx configuration explicitly returns 404 for is now denied in .htaccess as well. Resolves: nextcloud#63512 Signed-off-by: Stefan - ByteSide.io <sr@byteside.io>
|
I'm not sure adding all these exceptions is the best approach in the long run. Besides leading to a de facto "default allow" policy (for the involved extensions), which could bite us if we're not careful... It's also a maintenance headache to keep requiring customization of web server configurations. Other apps, such as Nextcloud Office, which have to serve a We could also make this way easier by implementing a counterpart to Thinking out loud here... I don't have a formal solution in mind at the moment. Just my gut and some random thoughts. |
Summary
The bundled pdf.js of
files_pdfviewerloads its localization fromapps/files_pdfviewer/js/pdfjs/web/locale/locale.jsonandapps/files_pdfviewer/js/pdfjs/web/locale/<lang>/viewer.ftl.Neither
jsonnorftlis part of the static file exclusion of the front controller rule thatSetup::updateHtaccess()writes when pretty URLs are enabled, so Apache routes both requests toindex.php, which answers404. pdf.js then fails to initialize and renders its alt text dialog instead of the document.Both extensions are added to that exclusion.
Why this does not widen what is reachable
.jsonand.ftlare already served statically in the two other supported setups:try_files $uri $uri/ /index.php$request_uri, so both are served there todayOnly Apache with pretty URLs behaves differently, and this change aligns it with the other two.
The one thing the nginx configuration does deny explicitly is package manager metadata:
.htaccesshas no equivalent, because with pretty URLs those paths happened to be swallowed by the front controller rule, and without pretty URLs they were reachable regardless. The same rule is therefore added to.htaccess, so that this change serves nothing that nginx would not serve, and the gap for installations without pretty URLs is closed along the way.Happy to drop that second hunk if you would rather keep this to the one-line fix.
Notes
locale.properties(Files_pdfviewer : localisation doesn't work with NC 29.0.7 files_pdfviewer#1191, PR fix: add properties files to htaccess rewrite condition #48692, closed without a merge). Upstream pdf.js has since moved to Fluent, which is why it islocale.jsonandviewer.ftlnow rather thanlocale.properties.lib/private/Setup.php; no test asserts its content..htaccessis hashed only up to#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####by the integrity checker, andcore/signature.jsonis generated at release time, so no signature needs regenerating here.nextcloud/documentationalready handles both extensions correctly, so no documentation change is required.Testing
Reproduction,
curloutput before/after and confirmation that the viewer works again are in #63512; the report was independently confirmed for 34.0.3 and 33.0.8.Checklist
.htaccessstable34andstable33if you agree, the issue is confirmed on both