Hi,

Enable CDN, for me my CDN tool is Amazon CloudFront.
When JS file are delivered by CDN, i can't edit content with CKEditor because my browser (Firefox) due to bad content mime type.
More info here: https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/X-Content-Type-Op...

Maybe this can help too: https://www.drupal.org/node/2854817

If i disable CDN, all is OK.

I hope it can help, i'm not sure if it's a CDN bug ou a bad Drupal core configuration.

Best regards,

Comments

max84 created an issue. See original summary.

wim leers’s picture

Thanks for reporting this issue! Looking into this now :)

wim leers’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)
due to bad content mime type.

Can you post a screenshot of what that response looks like?

Can you also please export your cdn.settings config? You can do that at /admin/config/development/configuration/single/export — it's of the "Simple configuration" configuration type.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I can't help you without more information. After >3 weeks of waiting for more information, I'm closing this, because it doesn't look like this information will ever follow.

Feel free to reopen!

millionleaves’s picture

Status: Closed (cannot reproduce) » Active

Re-opening.

I'm experiencing this issue. CKEditor doesn't work if CDN is enabled with Amazon Cloudfront.

Here's the log from the Chrome console. Let me know if you need more information.

randomcode.cloudfront.net/cdn/farfuture/vRNUFFoVIBLXYTJfjXQOupHs5I2VJig2Le9Fll-0LrU/1530738491/core/assets/vendor/ckeditor/lang/en.js?t=pbkn7i:1 Failed to load resource: the server responded with a status of 403 ()
edit?destination=/admin/commerce/products:1 Refused to execute script from 'https://randomcode.cloudfront.net/cdn/farfuture/vRNUFFoVIBLXYTJfjXQOupHs5I2VJig2Le9Fll-0LrU/1530738491/core/assets/vendor/ckeditor/lang/en.js?t=pbkn7i' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
ckeditor.js?v=4.8.0+2018-04-18-security-patch:235 Uncaught TypeError: Cannot set property 'dir' of undefined
    at Object.g (ckeditor.js?v=4.8.0+2018-04-18-security-patch:235)
    at a (ckeditor.js?v=4.8.0+2018-04-18-security-patch:236)
    at Array.n (ckeditor.js?v=4.8.0+2018-04-18-security-patch:236)
    at t (ckeditor.js?v=4.8.0+2018-04-18-security-patch:237)
    at HTMLScriptElement.CKEDITOR.env.ie.b.$.onerror (ckeditor.js?v=4.8.0+2018-04-18-security-patch:237)
edit?destination=/admin/commerce/products:1 Refused to apply style from 'https://randomcode.cloudfront.net/cdn/farfuture/vRNUFFoVIBLXYTJfjXQOupHs5I2VJig2Le9Fll-0LrU/1530738491/core/assets/vendor/ckeditor/skins/moono-lisa/editor.css?t=pbkn7i' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
js?callback=Drupal.geolocation.googleCallback&client=&key=AIzaSyAo76yFu77Qwv_lVqbeb1vZYKxyJdCohuQ&language=&libraries=&region=&v=&_=1531428939593:42 Google Maps JavaScript API error: DeletedApiProjectMapError
https://developers.google.com/maps/documentation/javascript/error-messages#deleted-api-project-map-error
_.Ib @ js?callback=Drupal.geolocation.googleCallback&client=&key=AIzaSyAo76yFu77Qwv_lVqbeb1vZYKxyJdCohuQ&language=&libraries=&region=&v=&_=1531428939593:42
edit?destination=/admin/commerce/products:1 Refused to apply style from 'https://randomcode.cloudfront.net/cdn/farfuture/vRNUFFoVIBLXYTJfjXQOupHs5I2VJig2Le9Fll-0LrU/1530738491/core/assets/vendor/ckeditor/skins/moono-lisa/editor.css?t=pbkn7i' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
wim leers’s picture

If you load https://randomcode.cloudfront.net/cdn/farfuture/vRNUFFoVIBLXYTJfjXQOupHs5I2VJig2Le9Fll-0LrU/1530738491/core/assets/vendor/ckeditor/lang/en.js?t=pbkn7i, what does the response look like?

millionleaves’s picture

I get an Access Denied error in Drupal.

When visiting using a web sniffer, I get the following response. The Expires line is obviously wrong.

Name	Value
HTTP/1.1 403 Forbidden
Content-Type:	text/html; charset=UTF-8
Transfer-Encoding:	chunked
Connection:	keep-alive
Date:	Mon, 16 Jul 2018 06:59:27 GMT
Server:	Apache/2.4.33 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.36
X-Content-Type-Options:	nosniff
X-Powered-By:	PHP/5.6.36
Cache-Control:	max-age=60, public
X-Drupal-Dynamic-Cache:	UNCACHEABLE
Link:	; rel="canonical", ; rel="shortlink"
Link:	; rel=preconnect; crossorigin
Link:	; rel=dns-prefetch
Link:	; rel="canonical", ; rel="shortlink"
Link:	; rel=preconnect; crossorigin
Link:	; rel=dns-prefetch
x-dns-prefetch-control:	on
X-UA-Compatible:	IE=edge
Content-Language:	en
X-Content-Type-Options:	nosniff
X-Frame-Options:	SAMEORIGIN
Expires:	Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified:	Mon, 16 Jul 2018 06:59:27 GMT
ETag:	"1531724367"
X-Generator:	Drupal 8 (https://www.drupal.org)
X-Drupal-Cache:	MISS
Vary:	Cookie
X-Cache:	Error from cloudfront
Via:	1.1 4b41f5d4002cf5daabe6e170bd619abc.cloudfront.net (CloudFront)
X-Amz-Cf-Id:	xDc_b8HzktahiEgFU9eSwd_FMUS12Dn4B0mxXSygYJjPYXhxHFeIoQ==
wim leers’s picture

What does the response body look like? Does it contain Invalid security token.?

wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

Without a response to #9, I can't help you. I really do want to help you!

millionleaves’s picture

Hi Wim.

Thanks. I messaged you privately via Drupal.org just after your last post a month or so ago. I'm guessing you didn't receive it?

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Postponed (maintainer needs more info) » Active

Ugh. I did, but I missed it. Sorry! Stay tuned.

wim leers’s picture

Title: CKEditor / X-Content-Type-Options » 403 due to invalid security token has terrible DX (was: "CKEditor / X-Content-Type-Options")
Category: Support request » Task
Issue tags: +DX (Developer Experience)

So you wrote

CKEditor doesn't work if CDN is enabled with Amazon Cloudfront.

… but since the response is a 403, of course it cannot work. Next step: figure out why it's a 403.

I'm 99% certain that this code in \Drupal\cdn\CdnFarfutureController::download() is causing the 403:

    // Validate security token.
    $root_relative_file_url = $request->query->get('root_relative_file_url');
    $calculated_token = Crypt::hmacBase64($mtime . $root_relative_file_url, $this->privateKey->get() . Settings::getHashSalt());
    if ($security_token !== $calculated_token) {
      throw new AccessDeniedHttpException('Invalid security token.');
    }

i.e. the provided security token is not matching, and AccessDeniedHttpException is converted to a HTML 403 response by \Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber::on403().

This is poor DX and should be fixed.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new767 bytes

This is a test-only patch that should fail, proving the DX problem described in #13.

wim leers’s picture

StatusFileSize
new419 bytes
new1.15 KB

And here's the fix.

wim leers’s picture

This should help confirm that it's indeed this "incorrect security token" that's causing the 403.

Next step: figuring out why that security token is invalid in your case. I'm assuming you did try clicking the "Clear all caches" button at /admin/config/development/performance?
Assuming you did, do you have any modules installed that extend/enhance/alter CKEditor?

The last submitted patch, 14: 2915417-14.patch, failed testing. View results

wim leers’s picture

Alright, that worked 👍

Now I need feedback for #16 :) It'd be great if you could apply #15 to your site and confirm that that 403 is no longer returning a HTML response, but just a plain text response containing:

Invalid security token.
wim leers’s picture

Status: Needs review » Postponed (maintainer needs more info)
millionleaves’s picture

Patch #15 applied, but I'm not seeing anything different in the Chrome console.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.96 KB
new1.82 KB

Sorry for not being more clear.

I never said that patch would fix your problem. I said it'd help confirm the root cause of the problem. I just checked the URL you sent me in private, and it almost is confirmed, but the concrete error message is missing. This should make that error message show up and confirm it 100%.

asak’s picture

I hit the same issues, tested the patch in 21 and i can confirm that the 403 now shows {"message":"Invalid security token."} instead of the Drupal "Access Denied" page when trying to access the file https://snap.mydomain.com/cdn/farfuture/LPro....J2A/1536185780/core/assets/vendor/ckeditor/lang/en.js?t=peomou.

So now that we know for certain that that is the actual problem - what's the fix? :)

wim leers’s picture

@asak Thanks for confirming!

I'll try to figure out how/why this is happening. Blocked on me now.

Vladimir Tanovic’s picture

I can confirm this issue exists too. I am using CDN module with KeyCDN provider and CKEditor crashes when JS files are served by CDN.

wim leers’s picture

Assigned: wim leers » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

wim leers’s picture