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
5package convert5package convert
6 6
7import (7import (
8 "net/url"
8 "time"9 "time"
9 10
10 "code.gitea.io/gitea/models"11 "code.gitea.io/gitea/models"
@@ -126,7 +127,7 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 115 unmodified lines
126 for i := 0; i < commit.ParentCount(); i++ {127 for i := 0; i < commit.ParentCount(); i++ {
127 sha, _ := commit.ParentID(i)128 sha, _ := commit.ParentID(i)
128 apiParents[i] = &api.CommitMeta{129 apiParents[i] = &api.CommitMeta{
129 URL: repo.APIURL() + "/git/commits/" + sha.String(),130 URL: repo.APIURL() + "/git/commits/" + url.PathEscape(sha.String()),
130 SHA: sha.String(),131 SHA: sha.String(),
131 }132 }
132 }133 }
@@ -147,13 +148,13 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 14 unmodified lines
147 148
148 return &api.Commit{149 return &api.Commit{
149 CommitMeta: &api.CommitMeta{150 CommitMeta: &api.CommitMeta{
150 URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),151 URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
151 SHA: commit.ID.String(),152 SHA: commit.ID.String(),
152 Created: commit.Committer.When,153 Created: commit.Committer.When,
153 },154 },
154 HTMLURL: repo.HTMLURL() + "/commit/" + commit.ID.String(),155 HTMLURL: repo.HTMLURL() + "/commit/" + url.PathEscape(commit.ID.String()),
155 RepoCommit: &api.RepoCommit{156 RepoCommit: &api.RepoCommit{
156 URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),157 URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
157 Author: &api.CommitUser{158 Author: &api.CommitUser{
158 Identity: api.Identity{159 Identity: api.Identity{
159 Name: commit.Author.Name,160 Name: commit.Author.Name,
@@ -170,7 +171,7 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 10 unmodified lines
170 },171 },
171 Message: commit.Message(),172 Message: commit.Message(),
172 Tree: &api.CommitMeta{173 Tree: &api.CommitMeta{
173 URL: repo.APIURL() + "/git/trees/" + commit.ID.String(),174 URL: repo.APIURL() + "/git/trees/" + url.PathEscape(commit.ID.String()),
174 SHA: commit.ID.String(),175 SHA: commit.ID.String(),
175 Created: commit.Committer.When,176 Created: commit.Committer.When,
176 },177 },

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