2017-07-12 20:28:52 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2022-09-03 00:48:23 +05:30
|
|
|
package integration
|
2017-07-12 20:28:52 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-09-03 00:48:23 +05:30
|
|
|
"code.gitea.io/gitea/tests"
|
2017-07-12 20:28:52 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestXSSUserFullName(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-08-16 07:52:25 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
2017-07-12 20:28:52 +05:30
|
|
|
const fullName = `name & <script class="evil">alert('Oh no!');</script>`
|
|
|
|
|
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
|
|
|
"name": user.Name,
|
|
|
|
"full_name": fullName,
|
|
|
|
"email": user.Email,
|
2020-12-04 11:50:30 +05:30
|
|
|
"language": "en-US",
|
2017-07-12 20:28:52 +05:30
|
|
|
})
|
2022-03-23 10:24:07 +05:30
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-07-12 20:28:52 +05:30
|
|
|
|
|
|
|
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(),
|
|
|
|
)
|
|
|
|
}
|