From 3b5f162fe6a387cac89f0c01e3ed4b279f09b27e Mon Sep 17 00:00:00 2001 From: forgejo-backport-action Date: Tue, 7 Jan 2025 19:01:32 +0000 Subject: [PATCH] [v10.0/forgejo] chore: remove illegal git usage (#6492) **Backport:** https://codeberg.org/forgejo/forgejo/pulls/6488 This is no longer possible in future go-git versions, so lets hardcode it Co-authored-by: Gusted Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6492 Co-authored-by: forgejo-backport-action Co-committed-by: forgejo-backport-action --- routers/web/repo/wiki_test.go | 4 +- .../a6/dc41d9e96df65286a79f5625ec51635e47f752 | Bin 0 -> 33 bytes .../df/6b6d9a97608bc8b56d4f30cde5af00f0681ccf | Bin 0 -> 262 bytes .../f5/4f5a6b7c4f83b606600e43186165854f189530 | Bin 0 -> 195 bytes .../user2/repo1.wiki.git/refs/heads/master | 2 +- tests/integration/api_wiki_test.go | 23 +++++ tests/integration/wiki_test.go | 2 +- tests/integration/xss_test.go | 83 ++++-------------- 8 files changed, 45 insertions(+), 69 deletions(-) create mode 100644 tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/a6/dc41d9e96df65286a79f5625ec51635e47f752 create mode 100644 tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/df/6b6d9a97608bc8b56d4f30cde5af00f0681ccf create mode 100644 tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/f5/4f5a6b7c4f83b606600e43186165854f189530 diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 47bad6d8e0..0c49e7d902 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -86,7 +86,7 @@ func TestWiki(t *testing.T) { Wiki(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) assert.EqualValues(t, "Home", ctx.Data["Title"]) - assertPagesMetas(t, []string{"Home", "Long Page", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"]) + assertPagesMetas(t, []string{"Home", "Long Page", "Page With Image", "Page With Spaced Name", "Unescaped File", "XSS"}, ctx.Data["Pages"]) } func TestWikiPages(t *testing.T) { @@ -96,7 +96,7 @@ func TestWikiPages(t *testing.T) { contexttest.LoadRepo(t, ctx, 1) WikiPages(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) - assertPagesMetas(t, []string{"Home", "Long Page", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"]) + assertPagesMetas(t, []string{"Home", "Long Page", "Page With Image", "Page With Spaced Name", "Unescaped File", "XSS"}, ctx.Data["Pages"]) } func TestNewWiki(t *testing.T) { diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/a6/dc41d9e96df65286a79f5625ec51635e47f752 b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/a6/dc41d9e96df65286a79f5625ec51635e47f752 new file mode 100644 index 0000000000000000000000000000000000000000..1aecac1f1b5c4bb92c58e2b2e2177cb51d8fc9b6 GIT binary patch literal 33 pcmb9GGs6`FfcPQQSivmP1VayVR+T_r@efUH~XP%EAKClN_3cu z?N&pT_~hrM>josIgVpWV^hil!%=>ktUAd6G)9A*b(?P*dbs#0W;h7~Fx}LdE)kd*L ze!MjCOUw8qYPM`{ysY0OAf2IbqV$*cwBr(@5(n8i1sUh> MX4v=#0GNJ$Z}5_Y{r~^~ literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/f5/4f5a6b7c4f83b606600e43186165854f189530 b/tests/gitea-repositories-meta/user2/repo1.wiki.git/objects/f5/4f5a6b7c4f83b606600e43186165854f189530 new file mode 100644 index 0000000000000000000000000000000000000000..a69fc579963ab58a63ad9706a917237d556f3540 GIT binary patch literal 195 zcmV;!06hPA0kx02PQySD0IB^IOPYX?U~Ql8A&f;wNs$K1_3j?AbdIg_C4#>P!8b7V zNTcCpo~Hs$2v;Smf`WuZplyYt z4Pq22s%tu5x1)1T#D|K`<+x;cId4U!-#AZe0Zz1SPdmL#X*W>PTyFNSM>s9l``gF< x;m;bNzfhXwSwCrBlin}+V}RPBwOwcs;SPVO`1hpfe>SRj`hvH^;Ty%~V015GVL<=@ literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master b/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master index c804802cbf..bd0c0d7efe 100644 --- a/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master +++ b/tests/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master @@ -1 +1 @@ -d49ac742d44063dcf69d4e0afe725813b777dd89 +f54f5a6b7c4f83b606600e43186165854f189530 diff --git a/tests/integration/api_wiki_test.go b/tests/integration/api_wiki_test.go index e086fa26af..638b90a4aa 100644 --- a/tests/integration/api_wiki_test.go +++ b/tests/integration/api_wiki_test.go @@ -224,6 +224,29 @@ func TestAPIListWikiPages(t *testing.T) { Message: "add unescaped file\n", }, }, + { + Title: "XSS", + HTMLURL: meta[5].HTMLURL, + SubURL: "XSS", + LastCommit: &api.WikiCommit{ + ID: "f54f5a6b7c4f83b606600e43186165854f189530", + Author: &api.CommitUser{ + Identity: api.Identity{ + Name: "Gusted", + Email: "valid@example.org", + }, + Date: "2024-01-31T00:00:00Z", + }, + Committer: &api.CommitUser{ + Identity: api.Identity{ + Name: "Gusted", + Email: "valid@example.org", + }, + Date: "2024-01-31T00:00:00Z", + }, + Message: "Yay XSS", + }, + }, } assert.Equal(t, dummymeta, meta) diff --git a/tests/integration/wiki_test.go b/tests/integration/wiki_test.go index 3e30b94486..30170086d2 100644 --- a/tests/integration/wiki_test.go +++ b/tests/integration/wiki_test.go @@ -61,7 +61,7 @@ func Test_RepoWikiPages(t *testing.T) { doc := NewHTMLParser(t, resp.Body) expectedPagePaths := []string{ - "Home", "Long-Page", "Page-With-Image", "Page-With-Spaced-Name", "Unescaped-File", + "Home", "Long-Page", "Page-With-Image", "Page-With-Spaced-Name", "Unescaped-File", "XSS", } doc.Find("tr").Each(func(i int, s *goquery.Selection) { firstAnchor := s.Find("a").First() diff --git a/tests/integration/xss_test.go b/tests/integration/xss_test.go index 70038cf560..6ac5b062f2 100644 --- a/tests/integration/xss_test.go +++ b/tests/integration/xss_test.go @@ -4,25 +4,16 @@ package integration import ( - "context" "fmt" "net/http" - "net/url" - "os" - "path/filepath" "testing" - "time" issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/tests" - gogit "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/object" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestXSSUserFullName(t *testing.T) { @@ -50,67 +41,29 @@ func TestXSSUserFullName(t *testing.T) { } func TestXSSWikiLastCommitInfo(t *testing.T) { - onGiteaRun(t, func(t *testing.T, u *url.URL) { - // Prepare the environment. - dstPath := t.TempDir() - r := fmt.Sprintf("%suser2/repo1.wiki.git", u.String()) - u, err := url.Parse(r) - require.NoError(t, err) - u.User = url.UserPassword("user2", userPassword) - require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{})) + defer tests.PrepareTestEnv(t)() + // Check on page view. + t.Run("Page view", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - // Use go-git here, because using git wouldn't work, it has code to remove - // `<`, `>` and `\n` in user names. Even though this is permitted and - // wouldn't result in a error by a Git server. - gitRepo, err := gogit.PlainOpen(dstPath) - require.NoError(t, err) + req := NewRequest(t, http.MethodGet, "/user2/repo1/wiki/XSS") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) - w, err := gitRepo.Worktree() - require.NoError(t, err) + htmlDoc.AssertElement(t, "script.evil", false) + assert.Contains(t, htmlDoc.Find(".ui.sub.header").Text(), `Gusted edited this page 2024-01-31`) + }) - filename := filepath.Join(dstPath, "Home.md") - err = os.WriteFile(filename, []byte("Oh, a XSS attack?"), 0o644) - require.NoError(t, err) + // Check on revisions page. + t.Run("Revision page", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - _, err = w.Add("Home.md") - require.NoError(t, err) + req := NewRequest(t, http.MethodGet, "/user2/repo1/wiki/XSS?action=_revision") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) - _, err = w.Commit("Yay XSS", &gogit.CommitOptions{ - Author: &object.Signature{ - Name: `Gusted`, - Email: "valid@example.org", - When: time.Date(2024, time.January, 31, 0, 0, 0, 0, time.UTC), - }, - }) - require.NoError(t, err) - - // Push. - _, _, err = git.NewCommand(git.DefaultContext, "push").AddArguments(git.ToTrustedCmdArgs([]string{"origin", "master"})...).RunStdString(&git.RunOpts{Dir: dstPath}) - require.NoError(t, err) - - // Check on page view. - t.Run("Page view", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req := NewRequest(t, http.MethodGet, "/user2/repo1/wiki/Home") - resp := MakeRequest(t, req, http.StatusOK) - htmlDoc := NewHTMLParser(t, resp.Body) - - htmlDoc.AssertElement(t, "script.evil", false) - assert.Contains(t, htmlDoc.Find(".ui.sub.header").Text(), `Gusted edited this page 2024-01-31`) - }) - - // Check on revisions page. - t.Run("Revision page", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req := NewRequest(t, http.MethodGet, "/user2/repo1/wiki/Home?action=_revision") - resp := MakeRequest(t, req, http.StatusOK) - htmlDoc := NewHTMLParser(t, resp.Body) - - htmlDoc.AssertElement(t, "script.evil", false) - assert.Contains(t, htmlDoc.Find(".ui.sub.header").Text(), `Gusted edited this page 2024-01-31`) - }) + htmlDoc.AssertElement(t, "script.evil", false) + assert.Contains(t, htmlDoc.Find(".ui.sub.header").Text(), `Gusted edited this page 2024-01-31`) }) }