Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
milahu opened this issue Feb 25, 2024 · 4 comments · Fixed by #29427
Closed

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

milahu opened this issue Feb 25, 2024 · 4 comments · Fixed by #29427
Labels
type/enhancement An improvement of existing functionality
Milestone

Comments

@milahu
Copy link

milahu commented 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

@lunny
Copy link
Member

lunny commented Feb 26, 2024

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

@lunny lunny added issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail and removed type/bug labels Feb 26, 2024
@milahu
Copy link
Author

milahu commented 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

@lunny lunny added type/enhancement An improvement of existing functionality and removed issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail labels Feb 26, 2024
@milahu
Copy link
Author

milahu commented 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>

@KN4CK3R
Copy link
Member

KN4CK3R commented 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

silverwind added a commit that referenced this issue Mar 13, 2024
)

Fixes #29404

Use relative links for
- commits
- mentions
- issues

---------

Co-authored-by: silverwind <me@silverwind.io>
@lunny lunny added this to the 1.22.0 milestone Mar 13, 2024
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants