2017-07-12 16:58:52 +02:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-16 09:53:21 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2017-07-12 16:58:52 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestXSSUserFullName(t *testing.T) {
|
2019-11-26 00:21:37 +01:00
|
|
|
defer prepareTestEnv(t)()
|
2021-11-24 10:49:20 +01:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
2017-07-12 16:58:52 +02: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{
|
|
|
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
|
|
|
"name": user.Name,
|
|
|
|
"full_name": fullName,
|
|
|
|
"email": user.Email,
|
2020-12-04 07:20:30 +01:00
|
|
|
"language": "en-US",
|
2017-07-12 16:58:52 +02:00
|
|
|
})
|
2022-03-23 05:54:07 +01:00
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-07-12 16:58:52 +02: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(),
|
|
|
|
)
|
|
|
|
}
|