forgejo/templates/repo/graph/commits.tmpl
zeripath bbffcc3aec
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>
2021-11-16 18:18:25 +00:00

78 lines
3.3 KiB
Handlebars

<div id="rev-container">
<ul id="rev-list">
{{ range $commitI, $commit := .Graph.Commits }}
<li {{if $commit.Rev}}id="commit-{{$commit.Rev}}"{{end}} data-flow="{{$commit.Flow}}">
{{ if $commit.OnlyRelation }}
<span></span>
{{ else }}
<span class="sha" id="{{$commit.ShortRev}}">
{{$class := "ui sha label"}}
{{if $commit.Commit.Signature}}
{{$class = (printf "%s%s" $class " isSigned")}}
{{if $commit.Verification.Verified}}
{{if eq $commit.Verification.TrustStatus "trusted"}}
{{$class = (printf "%s%s" $class " isVerified")}}
{{else if eq $commit.Verification.TrustStatus "untrusted"}}
{{$class = (printf "%s%s" $class " isVerifiedUntrusted")}}
{{else}}
{{$class = (printf "%s%s" $class " isVerifiedUnmatched")}}
{{end}}
{{else if $commit.Verification.Warning}}
{{$class = (printf "%s%s" $class " isWarning")}}
{{end}}
{{end}}
<a href="{{$.RepoLink}}/commit/{{$commit.Rev|PathEscape}}" rel="nofollow" class="{{$class}}">
<span class="shortsha">{{ShortSha $commit.Commit.ID.String}}</span>
{{- if $commit.Commit.Signature -}}
<span class="shortsha-pad"></span>{{template "repo/shabox_badge" dict "root" $ "verification" $commit.Verification}}
{{- end -}}
</a>
</span>
<span class="message df ac mr-2">{{RenderCommitMessage $commit.Subject $.RepoLink $.Repository.ComposeMetas}}</span>
<span class="tags df ac">
{{range $commit.Refs}}
{{$refGroup := .RefGroup}}
{{if eq $refGroup "pull"}}
{{if or (not $.HidePRRefs) (containGeneric $.SelectedBranches .Name)}}
<!-- it's intended to use issues not pulls, if it's a pull you will get redirected -->
<a class="ui labelled icon button basic tiny" href="{{$.RepoLink}}/{{if $.Repository.UnitEnabled $.UnitTypePullRequests}}pulls{{else}}issues{{end}}/{{.ShortName|PathEscape}}">
{{svg "octicon-git-pull-request" 16 "mr-2"}}#{{.ShortName}}
</a>
{{end}}
{{else if eq $refGroup "tags"}}
<a class="ui labelled icon button basic tiny" href="{{$.RepoLink}}/src/tag/{{.ShortName|PathEscape}}">
{{svg "octicon-tag" 16 "mr-2"}}{{.ShortName}}
</a>
{{else if eq $refGroup "remotes"}}
<a class="ui labelled icon button basic tiny" href="{{$.RepoLink}}/src/commit/{{$commit.Rev|PathEscape}}">
{{svg "octicon-cross-reference" 16 "mr-2"}}{{.ShortName}}
</a>
{{else if eq $refGroup "heads"}}
<a class="ui labelled icon button basic tiny" href="{{$.RepoLink}}/src/branch/{{.ShortName|PathEscape}}">
{{svg "octicon-git-branch" 16 "mr-2"}}{{.ShortName}}
</a>
{{else}}
<!-- Unknown ref type {{.Name}} -->
{{end}}
{{end}}
</span>
<span class="author df ac mr-2">
{{$userName := $commit.Commit.Author.Name}}
{{if $commit.User}}
{{if $commit.User.FullName}}
{{$userName = $commit.User.FullName}}
{{end}}
{{avatar $commit.User}}
<a href="{{$commit.User.HomeLink}}">{{$userName}}</a>
{{else}}
{{avatarByEmail $commit.Commit.Author.Email $userName}}
{{$userName}}
{{end}}
</span>
<span class="time df ac">{{$commit.Date}}</span>
{{ end }}
</li>
{{ end }}
</ul>
</div>