markdown: wrong hostname in commit url with empty ROOT_URL #12533

Closed
opened 2025-11-02 10:13:08 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @milahu on GitHub (Feb 25, 2024).

Description

when i leave ROOT_URL empty
then gitea uses http://localhost as hostname in commit urls
but gitea should produce urls without hostname

ping @KN4CK3R via #28909

repro https://try.gitea.io/milahu/test-gitea-markdown-wrong-commit-url

part of #19345

Gitea Version

1.21.6

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

gitea runs in a container on localhost, accessed from localhost
so gitea thinks that its hostname is "localhost", but that is wrong

Database

None

Originally created by @milahu on GitHub (Feb 25, 2024). ### Description when i leave ROOT_URL empty then gitea uses `http://localhost` as hostname in commit urls but gitea should produce urls without hostname ping @KN4CK3R via #28909 repro https://try.gitea.io/milahu/test-gitea-markdown-wrong-commit-url part of #19345 ### Gitea Version 1.21.6 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? gitea runs in a container on localhost, accessed from localhost so gitea thinks that its hostname is "localhost", but that is wrong ### Database None
GiteaMirror added the type/enhancement label 2025-11-02 10:13:08 -06:00
Author
Owner

@lunny commented on GitHub (Feb 26, 2024):

ROOT_URL is almost a MUST set option especially if you run gitea on the container.

@lunny commented on GitHub (Feb 26, 2024): `ROOT_URL` is almost a MUST set option especially if you run gitea on the container.
Author
Owner

@milahu commented on GitHub (Feb 26, 2024):

ROOT_URL is almost a MUST set option

that is the problem...
the same gitea instance should work on localhost and somewhere.com
and the localhost version should have no links to somewhere.com

this already works with file links, only commit links are broken

@milahu commented on GitHub (Feb 26, 2024): > `ROOT_URL` is almost a MUST set option that is the problem... the same gitea instance should work on `localhost` and `somewhere.com` and the `localhost` version should have no links to `somewhere.com` this already works with file links, only commit links are broken
Author
Owner

@milahu commented on GitHub (Feb 26, 2024):

in my gitea config, both DOMAIN and ROOT_URL are empty
so gitea should use no hostname in urls, just absolute paths like /explore/repos

[server]
DOMAIN =
ROOT_URL =

when urls with hostname are required
then gitea should use the actual hostname and port from the http request
but usually, browsers are smart enough to infer the full url from absolute paths

only commit links are broken

there are some other places where gitea uses localhost:12345

<link rel="manifest" href="data:application/json;base64,...">

decoded manifest json

{
  "name": "test",
  "short_name": "test",
  "start_url": "http://localhost:12345/",
  "icons": [
    {
      "src": "http://localhost:12345/assets/img/logo.png",
      "type": "image/png",
      "sizes": "512x512"
    },
    {
      "src": "http://localhost:12345/assets/img/logo.svg",
      "type": "image/svg+xml",
      "sizes": "512x512"
    }
  ]
}
<script>
	// ...
	// the escaped slashes look wrong
	window.config = {
		appUrl: 'http:\/\/localhost:12345\/',
<meta property="og:url" content="http://localhost:12345/someone/something">
<button class="ui small compact clone button" id="repo-clone-https" data-link="http://localhost:12345/someone/something.git">
	HTTPS
</button>
<input id="repo-clone-url" size="20" class="js-clone-url" value="http://localhost:12345/someone/something.git" readonly>
@milahu commented on GitHub (Feb 26, 2024): in my gitea config, both `DOMAIN` and `ROOT_URL` are empty so gitea should use no hostname in urls, just absolute paths like `/explore/repos` ``` [server] DOMAIN = ROOT_URL = ``` when urls with hostname are required then gitea should use the actual hostname and port from the http request but usually, browsers are smart enough to infer the full url from absolute paths > only commit links are broken there are some other places where gitea uses `localhost:12345` ```html <link rel="manifest" href="data:application/json;base64,..."> ``` decoded manifest json ```json { "name": "test", "short_name": "test", "start_url": "http://localhost:12345/", "icons": [ { "src": "http://localhost:12345/assets/img/logo.png", "type": "image/png", "sizes": "512x512" }, { "src": "http://localhost:12345/assets/img/logo.svg", "type": "image/svg+xml", "sizes": "512x512" } ] } ``` ```html <script> // ... // the escaped slashes look wrong window.config = { appUrl: 'http:\/\/localhost:12345\/', ``` ``` <meta property="og:url" content="http://localhost:12345/someone/something"> ``` ``` <button class="ui small compact clone button" id="repo-clone-https" data-link="http://localhost:12345/someone/something.git"> HTTPS </button> ``` ``` <input id="repo-clone-url" size="20" class="js-clone-url" value="http://localhost:12345/someone/something.git" readonly> ```
Author
Owner

@KN4CK3R commented on GitHub (Feb 26, 2024):

Gitea is currently not build to be fully domain independend and may never be. Some parts (like the commit url) can be transformed but that's not possible everywhere. Here is an issue with more information: #19345

@KN4CK3R commented on GitHub (Feb 26, 2024): Gitea is currently not build to be fully domain independend and may never be. Some parts (like the commit url) can be transformed but that's not possible everywhere. Here is an issue with more information: #19345
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12533