modxcms / revolution

MODX Revolution - Content Management Framework
https://modx.com/
GNU General Public License v2.0
1.35k stars 527 forks source link

[2.x] site_url returns IP address instead of domain url #16577

Open patrickatwsrn opened 2 months ago

patrickatwsrn commented 2 months ago

Bug report

Summary

Quick summary what's this issue about.

Today some image links returned a path that included the ipv6 address instead of the domain name.

<base href="[[!++site_url]]">

returns

base href="xxxx:xxxx:xxx:xxxx::1" 

instead of

base href="https://example.com/" 

This happens occationally (2-3 times per year) on other pages and I always "fix" it by hard-wiring the domain name into my tag.

I can also remember this problem to be popping up on acnchor links inside chunks using the scheme modifier.

[[~1? &scheme=full]]

Step to reproduce

It just happens, clearing the site cache solves the problem.

This seems to be a very old problem that occationally pops up:

(2011) https://forums.modx.com/thread/13720/site-url-returns-ip-address (2022) https://community.modx.com/t/links-randomly-changing-to-ip-address/5493

Observed behavior

n.a.

Expected behavior

In a single context environment, site_url should always return the domain name. In a multi-contecxt environment site_url should return the site_url of the current context.

Environment

MODX 2.8.6, PLESK Server running Ubuntu

ant-tar commented 2 months ago

I saw the same behavior once for 2.8.x, hard-coding solved the issue

jdaehne commented 2 months ago

I have the same behavior on a specific site on a specific hosting server. After clearing the MODX cache everything ist good again for a few month. Then suddenly it appears again.

Because this happens only on this server - I think it has to to with the hosting environment.

halftrainedharry commented 2 months ago

Like explained in the first link you posted, by default site_url is set for every request based on the request itself (in the file core/config/config.inc.php by using $_SERVER['HTTP_HOST'], $_SERVER['HTTPS'], etc.).

For example:

If site_url is always used uncached (e.g. [[!++site_url]]), this shouldn't create any issues. If site_url is used cached (e.g. [[++site_url]]), this can create issues, because the first request (after the cache is cleared) defines the value of site_url (in the cached file) for all future requests (until the cache is cleared again).


To avoid the problem, use site_url always uncached. Or you can create site_url/http_host context-settings/system-settings (to overwrite the generated values (from the request) in config.inc.php). Or maybe you can change the .htaccess file to make sure that your site is always accessed with the same %{HTTP_HOST} value.