-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Security #5
base: db2
Are you sure you want to change the base?
Security #5
Conversation
internal/http/utils/utils.go
Outdated
return fmt.Errorf("input is not a struct") | ||
} | ||
|
||
p := bluemonday.UGCPolicy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В доке bluemonday говорится, что политику надо создавать 1 раз, а не на каждый санитайзинг
Кстати, по идее можно было обойтись без санитайзинга на стороне бэка, у вас handlebars должен на фронте санитайзить. Но, конечно, лишним не будет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
поправил
if !checkPass(storedPassHash, password) { | ||
return models.User{}, fmt.Errorf("%s: %w", models.LevelDB, models.ErrInvalidPassword) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это должно происходить на уровне бизнес-логики
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
поправил
err = utils.SanitizeStruct(&req) | ||
if err != nil { | ||
h.logger.Error(r.Context(), "sanitize error", err) | ||
utils.WriteResponse(w, http.StatusInternalServerError, httpErrors.ErrInternal) | ||
return | ||
} | ||
|
||
_, err = govalidator.ValidateStruct(&req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если у вас всегда идет сначала санитайзинг, потом валидация, мб вынести в вспомогательную функцию? А то хэндлеры разрастаются
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
у ValidateStruct своя логика возврата ошибки и записи в ответ именно того поля, которое не прошло валидацию, если городить проверки откуда какую ошибку отправлять не очень читаемо выходит.
No description provided.