History

Multiple Escaping Improvements (#17551)

There are multiple places where Gitea does not properly escape URLs that it is building and there are multiple places where it builds urls when there is already a simpler function available to use this. This is an extensive PR attempting to fix these issues. 1. The first commit in this PR looks through all href, src and links in the Gitea codebase and has attempted to catch all the places where there is potentially incomplete escaping. 2. Whilst doing this we will prefer to use functions that create URLs over recreating them by hand. 3. All uses of strings should be directly escaped - even if they are not currently expected to contain escaping characters. The main benefit to doing this will be that we can consider relaxing the constraints on user names and reponames in future. 4. The next commit looks at escaping in the wiki and re-considers the urls that are used there. Using the improved escaping here wiki files containing '/'. (This implementation will currently still place all of the wiki files the root directory of the repo but this would not be difficult to change.) 5. The title generation in feeds is now properly escaped. 6. EscapePound is no longer needed - urls should be PathEscaped / QueryEscaped as necessary but then re-escaped with Escape when creating html with locales Signed-off-by: Andrew Thornton <art27@cantab.net>

zeripath committed 5 years ago

Commit bbffcc31 parent 7e1ae38153 files · +891 −712Browse files

Showing the changes to modules/convert/git_commit.go (1 of 153 files). Show all

Unified · Split

modules/convert/git_commit.go+6−5
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 package convert
66
77 import (
8+ "net/url"
89 "time"
910
1011 "code.gitea.io/gitea/models"
@@ -126,7 +127,7 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 115 unmodified lines
126127 for i := 0; i < commit.ParentCount(); i++ {
127128 sha, _ := commit.ParentID(i)
128129 apiParents[i] = &api.CommitMeta{
129− URL: repo.APIURL() + "/git/commits/" + sha.String(),
130+ URL: repo.APIURL() + "/git/commits/" + url.PathEscape(sha.String()),
130131 SHA: sha.String(),
131132 }
132133 }
@@ -147,13 +148,13 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 14 unmodified lines
147148
148149 return &api.Commit{
149150 CommitMeta: &api.CommitMeta{
150− URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
151+ URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
151152 SHA: commit.ID.String(),
152153 Created: commit.Committer.When,
153154 },
154− HTMLURL: repo.HTMLURL() + "/commit/" + commit.ID.String(),
155+ HTMLURL: repo.HTMLURL() + "/commit/" + url.PathEscape(commit.ID.String()),
155156 RepoCommit: &api.RepoCommit{
156− URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
157+ URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
157158 Author: &api.CommitUser{
158159 Identity: api.Identity{
159160 Name: commit.Author.Name,
@@ -170,7 +171,7 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 10 unmodified lines
170171 },
171172 Message: commit.Message(),
172173 Tree: &api.CommitMeta{
173− URL: repo.APIURL() + "/git/trees/" + commit.ID.String(),
174+ URL: repo.APIURL() + "/git/trees/" + url.PathEscape(commit.ID.String()),
174175 SHA: commit.ID.String(),
175176 Created: commit.Committer.When,
176177 },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t