Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update userinfo html xss

aichy1267666a89a6457
diff --git a/docs/docs.go b/docs/docs.go
index cce01432..1660ee72 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -2911,6 +2911,45 @@ const docTemplate = `{
}
}
},
+ "/answer/api/v1/post/render": {
+ "post": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "render post content",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Upload"
+ ],
+ "summary": "render post content",
+ "parameters": [
+ {
+ "description": "PostRenderReq",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.PostRenderReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/question": {
"put": {
"security": [
@@ -6589,6 +6628,14 @@ const docTemplate = `{
}
}
},
+ "schema.PostRenderReq": {
+ "type": "object",
+ "properties": {
+ "content": {
+ "type": "string"
+ }
+ }
+ },
"schema.QuestionAdd": {
"type": "object",
"required": [
diff --git a/docs/swagger.json b/docs/swagger.json
index 3503fce7..91ca0f4c 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -2899,6 +2899,45 @@
}
}
},
+ "/answer/api/v1/post/render": {
+ "post": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "render post content",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Upload"
+ ],
+ "summary": "render post content",
+ "parameters": [
+ {
+ "description": "PostRenderReq",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.PostRenderReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/question": {
"put": {
"security": [
@@ -6577,6 +6616,14 @@
}
}
},
+ "schema.PostRenderReq": {
+ "type": "object",
+ "properties": {
+ "content": {
+ "type": "string"
+ }
+ }
+ },
"schema.QuestionAdd": {
"type": "object",
"required": [
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index b02e9494..232fe850 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -976,6 +976,11 @@ definitions:
type:
type: string
type: object
+ schema.PostRenderReq:
+ properties:
+ content:
+ type: string
+ type: object
schema.QuestionAdd:
properties:
content:
@@ -3684,6 +3689,30 @@ paths:
summary: user's votes
tags:
- Activity
+ /answer/api/v1/post/render:
+ post:
+ consumes:
+ - application/json
+ description: render post content
+ parameters:
+ - description: PostRenderReq
+ in: body
+ name: data
+ required: true
+ schema:
+ $ref: '#/definitions/schema.PostRenderReq'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ security:
+ - ApiKeyAuth: []
+ summary: render post content
+ tags:
+ - Upload
/answer/api/v1/question:
delete:
consumes:
diff --git a/internal/service/user_service.go b/internal/service/user_service.go
index e7bd4374..306fea13 100644
--- a/internal/service/user_service.go
+++ b/internal/service/user_service.go
@@ -22,6 +22,7 @@ import (
usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/checker"
"github.com/google/uuid"
+ "github.com/microcosm-cc/bluemonday"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
"golang.org/x/crypto/bcrypt"
@@ -267,12 +268,17 @@ func (us *UserService) UpdateInfo(ctx context.Context, req *schema.UpdateInfoReq
if err != nil {
return nil, errors.BadRequest(reason.UserSetAvatar).WithError(err).WithStack()
}
+ xss := bluemonday.UGCPolicy()
+ bio := xss.Sanitize(
+ req.BioHTML,
+ )
+
userInfo := entity.User{}
userInfo.ID = req.UserID
userInfo.Avatar = string(avatar)
userInfo.DisplayName = req.DisplayName
userInfo.Bio = req.Bio
- userInfo.BioHTML = req.BioHTML
+ userInfo.BioHTML = bio
userInfo.Location = req.Location
userInfo.Website = req.Website
userInfo.Username = req.Username