Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
cache system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Dec 2011 at 18:54 UTC
Updated:
7 Jan 2016 at 17:15 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mfer commentedComment #2
pwolanin commentedTo clarify the problem here's an example - the filter cache may return content a rendered IMG tag (rendered, for example, by media module) that references a non-https URL if it was cached while begin viewed over http. This would lead to mixed content warnings for the page.
Comment #3
mfer commentedAfter working on an alternative database caching backend as an option in the interim I think I've come to the conclusion that core shouldn't attempt to automate checking if a cache should have a marker to signify https. It can work as a way around but isn't clean.
Instead, when something caches html that has absolute links in content or has the possibility of absolute links it should properly handle the cache id in a manner to reflect https if present. We should fix core to work this way, document this in the handbook/api docs, and file bugs against any modules we know violating this.
If that works as an idea I can start working on the patch.
Comment #4
drummFor the media example, I think a good solution is to avoid the problem and use a schemeless URI. I haven't seen a lot of info about them, I encountered them at #1180646: Linking to google_service.js with https protocol when SSL enabled. Seems like they are good to go, except for referencing style sheets, http://stackoverflow.com/questions/2181207/is-it-safe-to-use-schemeless-....
Comment #5
mfer commented@drumm Drupal 7 core uses an absolute URL for image style urls which is where media module gets the absolute url on images. This is a core behavior. Going schemaless would be nice and maybe something we should try getting into Drupal 8 and Drupal 7 contrib.
Comment #6
mfer commentedTo add a little more detail and context, file_create_url() takes internal Drupal paths (e.g., admin/modules) - that is those that don't start with a full domain or a / - and prepends them with the $base_url. This is how CSS and JavaScript end up with a full URL when rendered.
Comment #7
mfer commented@drumm I wrote up a description of how to implement protocol relative URLs in D7. That advice was very useful. http://engineeredweb.com/blog/11/12/protocol-relative-urls-drupal-7
Comment #8
dalinHTTPS isn't the only case where this can rear its head. If for example you want to route authenticated users through a separate domain for added security (via HTTP authentication, VPN, or something else), then you are also likely to see cached data containing the private domain. This can lead to random HTTP authentication popups, or just plain missing content.
Comment #9
Rob C commentedConfirming #8 Images uploaded via SSL are NOT visible on the Non-SSL site, link to the images is https://site/image.png while the request is done over http://site/image.png. (and we run on a self-signed certificate... boem... error) So, let's do some heavy url rewriting for now...
Comment #10
seanburlington commentedI'm running into this both for the http/https issue
But also because I'm have a cluster of servers, and depending on whether I want to access a single server or a load balancer I use different hostnames - but then I'm seeing these stored in the cache
I really want to just have relative urls in the page
Comment #11
effulgentsia commentedMarked #1032210: drupal_render_cid_parts() should add http vs. https protocol to cache keys a duplicate, so bringing over its tags to here.
I think we have these questions to figure out:
- For D8, should we switch to protocol relative URLs for everything except CSS?
- If yes to above, do we want to by default add protocol to the keys for caches mentioned in the issue summary anyway, so that we work with protocol absolute URLs added by contrib/custom code?
- If yes to above, do we want a way to easily toggle that behavior so that sites that stick to protocol relative URLs can get more cache reuse?
Comment #12
chemical commentedAs stated in #5:
is definitely the right way to do it.
#6 is spot on that this is an issue in file_create_url(). So it isn't a cache system issue but more a file system issue.
I have a patch made for D7 (see #1633558: file_create_url() changes relative URL to absolute URL for shipped files) which I am rewriting for D8 at the moment (at DrupalCon Munich).
Comment #13
chemical commentedThis patch change file_create_url() so schemeless urls are kept schemeless by expanding a path relative to the Drupal installation to absolute path of the web server.
Comment #15
chemical commentedUpdated patch to fix the 3 failed tests by using
$GLOBALS['base_path']instead of$GLOBALS['base_url'] . '/'and creating an absolute url for curl from a path (relative url) to reflect change of file_create_url() which no longer will add scheme to schemeless urls.Comment #16
effulgentsia commentedI'm not sure about this. This would fail to include the host name, so wouldn't be usable in an email or anywhere else absolute URLs are needed.
Comment #17
chemical commented@effulgentsia you are absolutely right that the use file_create_url() wouldn't work where absolute URLs are required when the function is used on schemeless URLs (paths).
The original first part of file_create_url():
Either all schemeless URLs passed to file_create_url() should be made absolute to ensure that they can be used in emails which would make caching very difficult to implement correctly or you should use the function url() to generate absolute URLs for emails which will give you complete control over how that resulting URLs look.
If schemeless URLs must be made absolute to make them useful in emails which protocol should added (http or https) and how to determine that—at the moment this depends on whether the action creating the email is done through https or not.
The real question is: When does Drupal Core need to generate absolute URLs for files inside the Drupal installation?
Comment #18
chemical commentedUpdated patch with some documentation about the return value.
I am still convinced that the api of file_create_url() is broken and schemeless paths should not have a scheme added. The behavior is a reminiscence from D6 where all file path are expanded to absolute urls. Further more the documentation of the function does not describe whether or not paths for shipped files are changed.
For a backport to D7 a variable could be used for switching between behavior. If the variable is set file_create_url() behaves as the old broken api if actually needed by any module.
Comment #19
chemical commentedStrange the same patch has been attached twice!?
Comment #20
liam morlandI have been working on a similar patch in #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send. Mine adds a parameter to file_create_url() allowing one to control whether or not an absolute URL is generated.
Comment #21
liam morlandReroll.
Comment #23
liam morlandComment #25
liam morlandComment #26
JeremyFrench commentedI think in general schemaless is ok, but it won't solve the issue if you need to server https content from a different domain than you do http. As could be the case if you were using a CDN, which didn't support SSL.
Comment #27
liam morlandReroll.
Comment #28
liam morlandReroll.
Comment #30
liam morland28: file_create_url_does_not_add_scheme_to_schemeless_url-1377840.patch queued for re-testing.
Comment #32
idebr commentedStraight reroll.
Comment #33
idebr commentedComment #35
idebr commentedI updated the tests added in #2276203: CSS Aggregation breaks URLs with Query String to assert a relative url.
Comment #38
deepakaryan1988Comment #39
deepakaryan1988Re-rolling the patch
Comment #40
deepakaryan1988Comment #41
deepakaryan1988Comment #43
deepakaryan1988Removing sprint weekend tag!!
As suggested by @YesCT
Comment #44
mfbThis honestly seems like a major bug for sites that are available on both HTTP and HTTPS. For example, the logo in the branding block could use an HTTP URL on HTTPS pages, which causes a mixed content warning.
Comment #45
mfbI didn't yet have a chance to read thru all of the above discussion, but I think adding url.site to the required_cache_contexts would be a reasonable solution for the problem I'm seeing:
required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions', 'url.site']Comment #46
dawehnerInteresting. I'm wondering whether we could switch to protocol relative URLs everywhere. This would allow us to not care about HTTP/HTTPs ... but yeah in reality url.site doesn't add a incredible big amount of additional cache entries, especially when in the future HTTPs will be the de facto standard
Comment #47
liam morlandEven better than protocol-relative URLs would be server-relative. There is a patch for that in #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send.
Comment #48
mfbLet's see if this passes tests.
Comment #49
berdirIt will certainly not pass since tons of tests are looking for cache contexts in various places.
Can't we instead make sure that we add that cache context where we don't already? I know that every absolute url generated through the UrlGenerator does add this, so those should be fine.
Comment #51
mfb46 tests to be exact. That sounds like a reasonable approach, if we can easily add cache context everywhere that the base URL is used.
Comment #52
webchickThis got brought up in the context of #2606918: [securelogin] Secure Login so calling this a contrib project blocker.
Comment #53
wim leers-1. We should only do that if absolutely necessary.
+1.
This will also be a problem for HTTP/2 support.
Comment #54
wim leersThis issue is equivalent with #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send. This issue is older, so strictly speaking we should be solving it here. But, #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send was much further along with a fix. So, closing this issue in favor of that one. A patch that is ready for final review is awaiting you there. Hopefully see you there!