Skip to content
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

Open
wants to merge 3 commits into
base: db2
Choose a base branch
from
Open

Security #5

wants to merge 3 commits into from

Conversation

source-Alexander-Rudenko
Copy link
Collaborator

No description provided.

return fmt.Errorf("input is not a struct")
}

p := bluemonday.UGCPolicy()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В доке bluemonday говорится, что политику надо создавать 1 раз, а не на каждый санитайзинг

Кстати, по идее можно было обойтись без санитайзинга на стороне бэка, у вас handlebars должен на фронте санитайзить. Но, конечно, лишним не будет

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поправил

Comment on lines 36 to 38
if !checkPass(storedPassHash, password) {
return models.User{}, fmt.Errorf("%s: %w", models.LevelDB, models.ErrInvalidPassword)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это должно происходить на уровне бизнес-логики

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поправил

Comment on lines +49 to 56
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если у вас всегда идет сначала санитайзинг, потом валидация, мб вынести в вспомогательную функцию? А то хэндлеры разрастаются

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у ValidateStruct своя логика возврата ошибки и записи в ответ именно того поля, которое не прошло валидацию, если городить проверки откуда какую ошибку отправлять не очень читаемо выходит.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants