mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
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> Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
@ -28,17 +28,17 @@
|
||||
{{ .OriginalAuthor }}
|
||||
</span>
|
||||
<span class="text grey">
|
||||
{{$.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}} {{if $.Repository.OriginalURL}}
|
||||
{{$.i18n.Tr "repo.issues.commented_at" (.Issue.HashTag|Escape) $createdStr | Safe}} {{if $.Repository.OriginalURL}}
|
||||
</span>
|
||||
<span class="text migrate">
|
||||
({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}}
|
||||
({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}}
|
||||
</span>
|
||||
{{else}}
|
||||
<span class="text grey">
|
||||
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>
|
||||
{{.Poster.GetDisplayName}}
|
||||
</a>
|
||||
{{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}
|
||||
{{$.i18n.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdStr | Safe}}
|
||||
</span>
|
||||
{{end}}
|
||||
</div>
|
||||
@ -124,18 +124,18 @@
|
||||
</a>
|
||||
<span class="text grey">
|
||||
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
|
||||
{{$link := printf "%s/commit/%s" $.Repository.HTMLURL $.Issue.PullRequest.MergedCommitID}}
|
||||
{{$link := printf "%s/commit/%s" $.Repository.HTMLURL ($.Issue.PullRequest.MergedCommitID|PathEscape)}}
|
||||
{{if eq $.Issue.PullRequest.Status 3}}
|
||||
{{$.i18n.Tr "repo.issues.manually_pull_merged_at" $link (ShortSha $.Issue.PullRequest.MergedCommitID) $.BaseTarget $createdStr | Str2html}}
|
||||
{{$.i18n.Tr "repo.issues.manually_pull_merged_at" ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID) ($.BaseTarget|Escape) $createdStr | Str2html}}
|
||||
{{else}}
|
||||
{{$.i18n.Tr "repo.issues.pull_merged_at" $link (ShortSha $.Issue.PullRequest.MergedCommitID) $.BaseTarget $createdStr | Str2html}}
|
||||
{{$.i18n.Tr "repo.issues.pull_merged_at" ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID) ($.BaseTarget|Escape) $createdStr | Str2html}}
|
||||
{{end}}
|
||||
</span>
|
||||
</div>
|
||||
{{else if eq .Type 3 5 6}}
|
||||
{{ $refFrom:= "" }}
|
||||
{{if ne .RefRepoID .Issue.RepoID}}
|
||||
{{ $refFrom = $.i18n.Tr "repo.issues.ref_from" .RefRepo.FullName }}
|
||||
{{ $refFrom = $.i18n.Tr "repo.issues.ref_from" (.RefRepo.FullName|Escape) }}
|
||||
{{end}}
|
||||
{{ $refTr := "repo.issues.ref_issue_from" }}
|
||||
{{if .Issue.IsPull}}
|
||||
@ -154,7 +154,7 @@
|
||||
{{if eq .RefAction 3}}<del>{{end}}
|
||||
<span class="text grey">
|
||||
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
|
||||
{{$.i18n.Tr $refTr .EventTag $createdStr .RefCommentHTMLURL $refFrom | Safe}}
|
||||
{{$.i18n.Tr $refTr (.EventTag|Escape) $createdStr (.RefCommentHTMLURL|Escape) $refFrom | Safe}}
|
||||
</span>
|
||||
{{if eq .RefAction 3}}</del>{{end}}
|
||||
|
||||
@ -414,7 +414,7 @@
|
||||
{{ .OriginalAuthor }}
|
||||
</span>
|
||||
<span class="text grey"> {{if $.Repository.OriginalURL}}</span>
|
||||
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
|
||||
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}}</span>
|
||||
{{else}}
|
||||
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
|
||||
{{end}}
|
||||
@ -444,7 +444,7 @@
|
||||
{{ .OriginalAuthor }}
|
||||
</span>
|
||||
<span class="text grey"> {{if $.Repository.OriginalURL}}</span>
|
||||
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
|
||||
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}}</span>
|
||||
{{else}}
|
||||
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
|
||||
{{end}}
|
||||
@ -542,11 +542,11 @@
|
||||
{{ .OriginalAuthor }}
|
||||
</span>
|
||||
<span class="text grey"> {{if $.Repository.OriginalURL}}</span>
|
||||
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
|
||||
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}}</span>
|
||||
{{else}}
|
||||
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
|
||||
{{end}}
|
||||
{{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdSubStr | Safe}}
|
||||
{{$.i18n.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdSubStr | Safe}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="comment-header-right actions df ac">
|
||||
@ -712,7 +712,7 @@
|
||||
<span class="text grey">
|
||||
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
|
||||
{{ if .IsForcePush }}
|
||||
{{$.i18n.Tr "repo.issues.force_push_codes" $.Issue.PullRequest.HeadBranch (ShortSha .OldCommit) ($.Issue.Repo.CommitLink .OldCommit) (ShortSha .NewCommit) ($.Issue.Repo.CommitLink .NewCommit) $createdStr | Safe}}
|
||||
{{$.i18n.Tr "repo.issues.force_push_codes" ($.Issue.PullRequest.HeadBranch|Escape) (ShortSha .OldCommit) (($.Issue.Repo.CommitLink .OldCommit)|Escape) (ShortSha .NewCommit) (($.Issue.Repo.CommitLink .NewCommit)|Escape) $createdStr | Safe}}
|
||||
{{else}}
|
||||
{{$.i18n.Tr (TrN $.i18n.Lang (len .Commits) "repo.issues.push_commit_1" "repo.issues.push_commits_n") (len .Commits) $createdStr | Safe}}
|
||||
{{end}}
|
||||
|
@ -6,13 +6,9 @@
|
||||
<div class="menu">
|
||||
{{ $referenceUrl := "" }}
|
||||
{{ if .issue }}
|
||||
{{ if .ctx.Issue.IsPull}}
|
||||
{{ $referenceUrl = Printf "%s%s/pulls/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }}
|
||||
{{ else }}
|
||||
{{ $referenceUrl = Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }}
|
||||
{{ end }}
|
||||
{{ $referenceUrl = Printf "%s#%s" .ctx.Issue.HTMLURL .item.HashTag }}
|
||||
{{ else }}
|
||||
{{ $referenceUrl = Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }}
|
||||
{{ $referenceUrl = Printf "%s/files#%s" .ctx.Issue.HTMLURL .item.HashTag }}
|
||||
{{ end }}
|
||||
<div class="item context" data-clipboard-text="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
|
||||
<div class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.ID}}">{{.ctx.i18n.Tr "repo.issues.context.quote_reply"}}</div>
|
||||
|
@ -86,7 +86,7 @@
|
||||
<div class="ui divider"></div>
|
||||
<div class="review-item">
|
||||
<div class="review-item-left">
|
||||
<a href="{{$.Repository.OriginalURL}}" class="ui poping up" data-content="{{$.i18n.Tr "repo.migrated_from_fake" $.Repository.GetOriginalURLHostname | Safe }}">
|
||||
<a href="{{$.Repository.OriginalURL}}" class="ui poping up" data-content="{{$.i18n.Tr "repo.migrated_from_fake" ($.Repository.GetOriginalURLHostname|Escape) | Safe }}">
|
||||
<span class="text black ">
|
||||
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
|
||||
{{ .OriginalAuthor }}
|
||||
@ -133,11 +133,11 @@
|
||||
{{if .Issue.PullRequest.HasMerged}}
|
||||
<div class="item text">
|
||||
{{if .Issue.PullRequest.MergedCommitID}}
|
||||
{{$link := printf "%s/commit/%s" $.Repository.HTMLURL .Issue.PullRequest.MergedCommitID}}
|
||||
{{$link := printf "%s/commit/%s" $.Repository.HTMLURL (.Issue.PullRequest.MergedCommitID|PathEscape)}}
|
||||
{{if eq $.Issue.PullRequest.Status 3}}
|
||||
{{$.i18n.Tr "repo.pulls.manually_merged_as" $link (ShortSha .Issue.PullRequest.MergedCommitID) | Safe}}
|
||||
{{$.i18n.Tr "repo.pulls.manually_merged_as" ($link|Escape) (ShortSha .Issue.PullRequest.MergedCommitID) | Safe}}
|
||||
{{else}}
|
||||
{{$.i18n.Tr "repo.pulls.merged_as" $link (ShortSha .Issue.PullRequest.MergedCommitID) | Safe}}
|
||||
{{$.i18n.Tr "repo.pulls.merged_as" ($link|Escape) (ShortSha .Issue.PullRequest.MergedCommitID) | Safe}}
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{$.i18n.Tr "repo.pulls.has_merged"}}
|
||||
@ -177,7 +177,7 @@
|
||||
{{$.i18n.Tr "repo.pulls.data_broken"}}
|
||||
</div>
|
||||
{{else if .IsPullWorkInProgress}}
|
||||
<div class="item toggle-wip df ac sb" data-title="{{.Issue.Title}}" data-wip-prefix="{{(.WorkInProgressPrefix|Escape)}}" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">
|
||||
<div class="item toggle-wip df ac sb" data-title="{{.Issue.Title}}" data-wip-prefix="{{(.WorkInProgressPrefix|Escape)}}" data-update-url="{{.Issue.Link}}/title">
|
||||
<div>
|
||||
<i class="icon icon-octicon">{{svg "octicon-x"}}</i>
|
||||
{{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" }}
|
||||
|
@ -79,7 +79,7 @@
|
||||
{{end}}
|
||||
{{range .OriginalReviews}}
|
||||
<div class="item" style="margin-bottom: 10px;">
|
||||
<a href="{{$.Repository.OriginalURL}}" class="ui poping up" data-content="{{$.i18n.Tr "repo.migrated_from_fake" $.Repository.GetOriginalURLHostname | Safe }}">
|
||||
<a href="{{$.Repository.OriginalURL}}" class="ui poping up" data-content="{{$.i18n.Tr "repo.migrated_from_fake" ($.Repository.GetOriginalURLHostname|Escape) | Safe }}">
|
||||
<span class="text black">
|
||||
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
|
||||
{{ .OriginalAuthor }}
|
||||
@ -97,7 +97,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}}
|
||||
<div class="toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{(index .PullRequestWorkInProgressPrefixes 0| Escape)}}" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">
|
||||
<div class="toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{(index .PullRequestWorkInProgressPrefixes 0| Escape)}}" data-update-url="{{.Issue.Link}}/title">
|
||||
<a class="muted">
|
||||
{{.i18n.Tr "repo.pulls.still_in_progress"}} {{.i18n.Tr "repo.pulls.add_prefix" (index .PullRequestWorkInProgressPrefixes 0| Escape) | Safe}}
|
||||
</a>
|
||||
@ -321,7 +321,7 @@
|
||||
<div class="ui watching">
|
||||
<span class="text"><strong>{{.i18n.Tr "notification.notifications"}}</strong></span>
|
||||
<div class="mt-3">
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/watch">
|
||||
<form method="POST" action="{{.Issue.Link}}/watch">
|
||||
<input type="hidden" name="watch" value="{{if $.IssueWatch.IsWatching}}0{{else}}1{{end}}" />
|
||||
{{$.CsrfTokenHtml}}
|
||||
<button class="fluid ui button df jc">
|
||||
@ -343,10 +343,10 @@
|
||||
<div class="ui timetrack">
|
||||
<span class="text"><strong>{{.i18n.Tr "repo.issues.tracker"}}</strong></span>
|
||||
<div class="mt-3">
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/times/stopwatch/toggle" id="toggle_stopwatch_form">
|
||||
<form method="POST" action="{{.Issue.Link}}/times/stopwatch/toggle" id="toggle_stopwatch_form">
|
||||
{{$.CsrfTokenHtml}}
|
||||
</form>
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/times/stopwatch/cancel" id="cancel_stopwatch_form">
|
||||
<form method="POST" action="{{.Issue.Link}}/times/stopwatch/cancel" id="cancel_stopwatch_form">
|
||||
{{$.CsrfTokenHtml}}
|
||||
</form>
|
||||
{{if $.IsStopwatchRunning}}
|
||||
@ -355,14 +355,14 @@
|
||||
{{else}}
|
||||
{{if .HasUserStopwatch}}
|
||||
<div class="ui warning message">
|
||||
{{.i18n.Tr "repo.issues.tracking_already_started" .OtherStopwatchURL | Safe}}
|
||||
{{.i18n.Tr "repo.issues.tracking_already_started" (.OtherStopwatchURL|Escape) | Safe}}
|
||||
</div>
|
||||
{{end}}
|
||||
<button class="ui fluid button poping up issue-start-time" data-content='{{.i18n.Tr "repo.issues.start_tracking"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.start_tracking_short"}}</button>
|
||||
<div class="ui mini modal issue-start-time-modal">
|
||||
<div class="header">{{.i18n.Tr "repo.issues.add_time"}}</div>
|
||||
<div class="content">
|
||||
<form method="POST" id="add_time_manual_form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/times/add" class="ui action input fluid">
|
||||
<form method="POST" id="add_time_manual_form" action="{{.Issue.Link}}/times/add" class="ui action input fluid">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<input placeholder='{{.i18n.Tr "repo.issues.add_time_hours"}}' type="number" name="hours">
|
||||
<input placeholder='{{.i18n.Tr "repo.issues.add_time_minutes"}}' type="number" name="minutes" class="ui compact">
|
||||
@ -429,7 +429,7 @@
|
||||
|
||||
{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}
|
||||
<div {{if ne .Issue.DeadlineUnix 0}} style="display: none;"{{end}} id="deadlineForm">
|
||||
<form class="ui fluid action input issue-due-form" action="{{AppSubUrl}}/api/v1/repos/{{.Repository.Owner.Name}}/{{.Repository.Name}}/issues/{{.Issue.Index}}" method="post" id="update-issue-deadline-form">
|
||||
<form class="ui fluid action input issue-due-form" action="{{AppSubUrl}}/api/v1/repos/{{PathEscape .Repository.Owner.Name}}/{{PathEscape .Repository.Name}}/issues/{{.Issue.Index}}" method="post" id="update-issue-deadline-form">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<input required placeholder="{{.i18n.Tr "repo.issues.due_date_form"}}" {{if gt .Issue.DeadlineUnix 0}}value="{{.Issue.DeadlineUnix.Format "2006-01-02"}}"{{end}} type="date" name="deadlineDate" id="deadlineDate">
|
||||
<button class="ui green icon button">
|
||||
@ -468,7 +468,7 @@
|
||||
{{range .BlockingDependencies}}
|
||||
<div class="item dependency{{if .Issue.IsClosed}} is-closed{{end}} df ac sb">
|
||||
<div class="item-left df jc fc f1">
|
||||
<a class="title" href="{{.Repository.Link}}/issues/{{.Issue.Index}}">
|
||||
<a class="title" href="{{.Issue.Link}}">
|
||||
#{{.Issue.Index}} {{.Issue.Title | RenderEmoji}}
|
||||
</a>
|
||||
<div class="text small">
|
||||
@ -495,7 +495,7 @@
|
||||
{{range .BlockedByDependencies}}
|
||||
<div class="item dependency{{if .Issue.IsClosed}} is-closed{{end}} df ac sb">
|
||||
<div class="item-left df jc fc f1">
|
||||
<a class="title" href="{{.Repository.Link}}/{{if .Issue.IsPull}}pulls{{else}}issues{{end}}/{{.Issue.Index}}">
|
||||
<a class="title" href="{{.Issue.Link}}">
|
||||
#{{.Issue.Index}} {{.Issue.Title | RenderEmoji}}
|
||||
</a>
|
||||
<div class="text small">
|
||||
@ -516,7 +516,7 @@
|
||||
|
||||
{{if and .CanCreateIssueDependencies (not .Repository.IsArchived)}}
|
||||
<div>
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/dependency/add" id="addDependencyForm">
|
||||
<form method="POST" action="{{.Issue.Link}}/dependency/add" id="addDependencyForm">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<div class="ui fluid action input">
|
||||
<div class="ui search selection dropdown" id="new-dependency-drop-list" data-issue-id="{{.Issue.ID}}">
|
||||
@ -543,7 +543,7 @@
|
||||
{{.i18n.Tr "repo.issues.dependency.remove_header"}}
|
||||
</div>
|
||||
<div class="content">
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/dependency/delete" id="removeDependencyForm">
|
||||
<form method="POST" action="{{.Issue.Link}}/dependency/delete" id="removeDependencyForm">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<input type="hidden" value="" name="removeDependencyID" id="removeDependencyID"/>
|
||||
<input type="hidden" value="" name="dependencyType" id="dependencyType"/>
|
||||
@ -601,7 +601,7 @@
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<form class="ui form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}{{ if .Issue.IsLocked }}/unlock{{else}}/lock{{end}}"
|
||||
<form class="ui form" action="{{.Issue.Link}}{{ if .Issue.IsLocked }}/unlock{{else}}/lock{{end}}"
|
||||
method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
|
||||
|
Reference in New Issue
Block a user