From 1a414d88297eec8f2bdf3a0155fbab9f695f1bea Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 16:02:46 -1000 Subject: Test markup in refs, names and messages No test gave a ref name, a commit or tag message, a note or an ident any markup, and the one hostile file name never reached an attribute. html_txt leaves quotes alone, so a name holding both a quote and a bracket is what tells an attribute written as text. --- tests/t0301-security.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests') diff --git a/tests/t0301-security.sh b/tests/t0301-security.sh index 092e0a9..dac5c39 100755 --- a/tests/t0301-security.sh +++ b/tests/t0301-security.sh @@ -501,4 +501,58 @@ test_expect_success 'repository bytes go out under a policy that loads nothing' test_grep "^Content-Security-Policy: default-src .none.$" tmp ' +# Ref names, file names, messages and idents are all written by whoever can +# push, and git takes quotes, an ampersand and angle brackets in each, apart +# from the brackets in a name. Each has to be escaped for the context it +# lands in, and html_txt leaves quotes alone, so only a name holding both a +# quote and a bracket tells an attribute escaped as text. +test_expect_success 'set up a repository whose names and messages hold markup' ' + mkrepo repos/mk 1 && + ( + cd repos/mk && + echo hi >"$(printf "f\047\"&.txt")" && + git add -A && + GIT_AUTHOR_NAME="au & \"q\" '\''s" GIT_COMMITTER_NAME="co & \"q\" '\''s" \ + git commit -m "subject & \"q\" '\''s" -m "body & \"q\" '\''s" && + git branch "br'\''\"&" && + GIT_COMMITTER_NAME="tagger & \"q\" t" git tag -a -m "tag & \"q\"" "tg'\''\"&" && + git notes add -m "note & \"q\"" + ) && + cgitrc_repo mkrc mk snapshots=tar.gz +' + +test_expect_success 'names and messages holding markup are escaped on every page' ' + cgit_ok mkrc "url=mk/" >tmp && + test_grep "" tmp && + test_grep "br.\"<x>&" tmp && + test_grep "tg.\"<x>&" tmp && + test_grep "mk-tg.\"<x>&.tar.gz" tmp && + test_grep "au & \"q\" .s" tmp && + test_grep "tagger & \"q\" t" tmp && + test_grep ! "" tmp && + cgit_ok mkrc "url=mk/log/" >tmp && + test_grep ">subject <x> & \"q\" .s" tmp && + test_grep "br.\"<x>&" tmp && + test_grep ! "" tmp && + cgit_ok mkrc "url=mk/commit/" >tmp && + test_grep "
subject <x> & \"q\" .s<" tmp && + test_grep "
body <x> & \"q\" .s" tmp && + test_grep "
note <x> & \"q\"" tmp && + test_grep "co & \"q\" .s" tmp && + test_grep "
" tmp && + test_grep ! "" tmp && + cgit_ok mkrc "url=mk/commit/&dt=1" >tmp && + test_grep "" tmp && + test_grep ! "" tmp && + cgit_ok mkrc "url=mk/tag/&h=tg%27%22%3Cx%3E%26" >tmp && + test_grep "
tag <x> & \"q\"
" tmp && + test_grep "tagger & \"q\" t" tmp && + test_grep ! "" tmp && + cgit_ok mkrc "url=mk/atom/" >tmp && + test_grep "subject <x> & \"q\" .s" tmp && + test_grep "body <x> & \"q\" .s" tmp && + test_grep "au & \"q\" .s" tmp && + test_grep ! "" tmp +' + test_done -- cgit 2.12.1