2017-07-12 16:58:52 +02:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-07-12 16:58:52 +02:00
|
|
|
|
2022-09-02 21:18:23 +02:00
|
|
|
package integration
|
2017-07-12 16:58:52 +02:00
|
|
|
|
|
|
|
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"
|
2022-09-02 21:18:23 +02:00
|
|
|
"code.gitea.io/gitea/tests"
|
2017-07-12 16:58:52 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestXSSUserFullName(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-08-16 04:22:25 +02:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
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(),
|
|
|
|
)
|
|
|
|
}
|