제출 된 데이터를 지정된 struct에 마샬링하기 직전에 입력을 위생적으로 처리하려고합니다.golang에서 입력 데이터를 어떻게 위생 처리합니까?
다음은 현재 사용중인 모델입니다. 여기
type Post struct {
Id int `json:"Id"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
CreatorId int `json:"CreatorId"`
Creator *User
Editors []int `json:"Editors"`
Status Status `json:"Status"`
Title string `json:"Title"`
ShortDescription string `json:"ShortDescription"`
Description string `json:"Description"`
Content string `json:"Content"`
Url string `json:"Url"`
Media *Media
Categories []Category `json:"Categories"`
Tags []Tag `json:"Tags"`
MediaId int `json:"MediaId"`
Keywords string `json:"Keywords"`
Data []string `json:"Data"`
}
는 가능한 전송 JSON 데이터의 예이다 I 가장 효과적으로 따라서 임의의 제거,이 과정에서
ReadJSON
요청시에 데이터를 삽입하기 전에 상기 JSON 폼 데이터 살균 얼마나
{"Id":1,"CreatedAt":"2016-10-11T21:29:46.134+02:00","UpdatedAt":"0001-01-01T00:00:00Z","CreatorId":1,"Editors":null,"Status":1,"Title":"This is the title of the first post, to be changed.<script>alert()</script>","ShortDescription":"this is the short description of this post","Description":"","Content":"Contrary to popular belief Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC making it over 2000 years old. Richard McClintock","Url":"lorem-ipsum-first"}
<script>alert()</script>.
과 같은 악의적 인 코드? 사용할 수있는 추가 정보가있는 경우 요청하십시오. 추가 할 수있게되어 기쁩니다. 감사합니다.
당신은 아마이 읽어야 : 당신이 당신의 이동 프로젝트를 위해 조리개를 사용하지 말아야하는 이유 (HTTP :
검증에 사용되는 패키지는
gopkg.in/validator.v2
사용입니다 // www가 .florinpatan.ro/2016/10/why-you-should-not-use-iris-for-your-go.html). 나는 당신이 전환 할 필요가 없다는 말은 아니지만 적어도 지역 사회의 많은 사람들이 아이리스에 관해 갖고있는 우려 사항을 알고 있어야합니다. – joshlf
실제로 Go에서 프레임 워크를 사용할 이유가 없습니다. Go에 관해서 가장 좋아하는 것 같습니다 Go –
적어도 적어도 나중에는 알았습니다. –