Links don't vary for single site with multiple hostnames

Created on 28 June 2024, 11 months ago

Problem/Motivation

When a single site has multiple hostnames (e.g. www.example.com and www-cms.example.com), a race condition occurs in which the first hostname served is used for all hostnames.

Using the previous example, if the first page load is for www-cms.example.com, then pages loaded from www.example.com will have their favicon links rendered to load from www-cms.example.com

To be clear, the www and www-cms sites are meant to be serving the same content. In my particular use case, www is intended to be accessed by the general public while www-cms is used to edit site content.

Steps to reproduce

  1. Create a single site which responds to both www.example.com and www-cms.example.com
  2. Set up favicons via the `resposive_favicons` modules (the exact settings should not matter).
  3. Clear all caches.
  4. Access the site via www-cms.example.com
  5. Access the site a second time, via www.example.com
  6. View the page source from www.example.com

The favicon links on www.example.com will reflect www-cms.example.com.

Proposed resolution

I believe this can be remedied by setting the cache context to 'url.site'.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • A patch for this issue. The approach is to vary the cache-id to distinguish between sites. This causes the favicon paths to mirror the hostnames they'll be retrieved from (e.g. https://example.com vs https://www.example.com) and avoid CORS errors on any manifest files.

  • 🇫🇷France mably

    Fixing this looks like it will also solve the problem with the domain module: #2968070: Support the domain module .

  • 🇫🇷France mably

    @blairlearn is it still a problem?

    It's looks like all links and metatags URLs are relative, so I can't see where the problem is exactly.

    And changing the cache id won't change the pregenerated icons' URLs.

  • @mably Yes. This is still a problem.

    The change to the cache-id varies it to include the hostname. On a site with multiple domains, e.g. example.com and www.example.com, you end up with the cache-id being responsive_favicons.example.com:icons or responsive_favicons.www.example.com:icons, depending on which was used for the request.

    Our sites typically have four domain names, this patch has been serving us well for the past nine months.

  • 🇫🇷France mably

    I sadly still doesn't understand what the problem is exactly...

    Are you using the Domain module ?

  • Our individual sites have multiple hostnames. Without going too deeply into it, we'll have something like mysite.example.org and mysite-prod.example.com pointed at the same instance. Among other things, this is useful for migrations where we want to be able to keep mysite.example.com pointed at the old server until all the content is ready to go live. (This is one scenario, we typically have as many as four names/domains pointed to a single site.)

    The responsive favicons UI uses relative URL (e.g. /site.webmanifest), but these are rendered in the head block as absolute URLs, which are then cached. So if the first user to visit the site comes in via mysite.example.org, the URL for the manifest that will be cached is https://mysite.example.org/site.webmanifest.

    The problem comes in when a user visits the site via any of the other hostnames. If the first visit is to mysite.example.org, anyone visiting mysite-prod.example.org will be served cached HTML with the manifest URL pointing to mysite.example.org instead of mysite-prod.example.org. This results in a CORS error.

    Similarly, a reference to /favicon.svg will be cached as https://mysite.example.org/favicon.svg. (I don't recall for certain whether the favicons themselves result in CORS messages.

    We are not using the domain module (though the similarities occurred to me as well after the patch was written). Our sites are hosted on Acquia, but I've been able to duplicate and debug the issue using host file entries that resolve to localhost.

  • 🇫🇷France mably

    Ok, thanks for your clarifcation, I think I get the idea.

    On our side all the URLs are kept relatives on the page.

    Is it mandatory on your side to have those absolute URLs?

  • This is interesting. My first thought was to wonder if we're both looking at the same code and the answer is, we are not.

    I hadn't realized it until now, but the absolute URLs are a result of the patch for the subfolder issue 🐛 Incorrect path if Drupal is installed in subfolder Active . A previous developer had determined this was necessary because our hosting arrangement allows us to have "microsites" so that one Drupal site is served as a "subdirectory" of another. e.g. https://mysite.example.com/myothersite. (My understanding is that the hosting provider uses something based on "Drupal Gardens")

    Thanks for your time in helping us understand what's going on.

Production build 0.71.5 2024