2017-07-12 08:58:52 -06:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-07-12 08:58:52 -06:00
|
|
|
|
2022-09-02 13:18:23 -06:00
|
|
|
package integration
|
2017-07-12 08:58:52 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-16 01:53:21 -07:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 02:49:20 -07:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-09-02 13:18:23 -06:00
|
|
|
"code.gitea.io/gitea/tests"
|
2017-07-12 08:58:52 -06:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestXSSUserFullName(t *testing.T) {
|
2022-09-02 13:18:23 -06:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-08-15 20:22:25 -06:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
2017-07-12 08:58:52 -06:00
|
|
|
const fullName = `name & <script class="evil">alert('Oh no!');</script>`
|
|
|
|
|
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
2024-10-09 21:48:21 -06:00
|
|
|
"_csrf": GetUserCSRFToken(t, session),
|
2017-07-12 08:58:52 -06:00
|
|
|
"name": user.Name,
|
|
|
|
"full_name": fullName,
|
|
|
|
"email": user.Email,
|
2020-12-03 23:20:30 -07:00
|
|
|
"language": "en-US",
|
2017-07-12 08:58:52 -06:00
|
|
|
})
|
2022-03-22 22:54:07 -06:00
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-07-12 08:58:52 -06:00
|
|
|
|
|
|
|
req = NewRequestf(t, "GET", "/%s", user.Name)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
assert.EqualValues(t, 0, htmlDoc.doc.Find("script.evil").Length())
|
|
|
|
assert.EqualValues(t, fullName,
|
|
|
|
htmlDoc.doc.Find("div.content").Find(".header.text.center").Text(),
|
|
|
|
)
|
|
|
|
}
|