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

Improve PUT /deliveryservice_request_comments id validation #8071

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7918](https://github.com/apache/trafficcontrol/pull/7918) *Traffic Portal* Fixed topology link under DS-Servers tables page
- [#7846](https://github.com/apache/trafficcontrol/pull/7846) *Traffic Portal* Increase State character limit
- [#8010](https://github.com/apache/trafficcontrol/pull/8010) *Traffic Stats* Omit NPM dev dependencies from Traffic Stats RPM
- [#8071](https://github.com/apache/trafficcontrol/pull/8071) *Traffic Ops* Improve validation for the `id` field of the `PUT /deliveryservice_request_comments` endpoint.

### Removed
- [#7832](https://github.com/apache/trafficcontrol/pull/7832) *t3c* Removed Perl dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func Get(w http.ResponseWriter, r *http.Request) {
// Validate is used to ensure that the DeliveryServiceRequestCommentV5 struct passed in to the function is valid.
func Validate(dsrc tc.DeliveryServiceRequestCommentV5) error {
errs := validation.Errors{
"id": validation.Validate(dsrc.ID, validation.NotNil),
"deliveryServiceRequestId": validation.Validate(dsrc.DeliveryServiceRequestID, validation.NotNil),
"value": validation.Validate(dsrc.Value, validation.NotNil),
}
Expand All @@ -286,14 +287,21 @@ func Update(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
}
idParam := inf.Params["id"]
id, parseErr := strconv.Atoi(idParam)
if parseErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("id must be an integer"), nil)
return
}
deliveryServiceRequestComment.ID = id

if err := Validate(deliveryServiceRequestComment); err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
}

var current tc.DeliveryServiceRequestCommentV5
err := inf.Tx.QueryRowx(selectQuery() + `WHERE dsrc.id=` + inf.Params["id"]).StructScan(&current)
err := inf.Tx.QueryRowx(selectQuery() + `WHERE dsrc.id=` + strconv.Itoa(deliveryServiceRequestComment.ID)).StructScan(&current)
if err != nil {
api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning deliveryservice_request_comment: "+err.Error()))
return
Expand All @@ -305,13 +313,6 @@ func Update(w http.ResponseWriter, r *http.Request) {
return
}
deliveryServiceRequestComment.AuthorID = current.AuthorID
idParam := inf.Params["id"]
id, parseErr := strconv.Atoi(idParam)
if parseErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("id must be an integer"), nil)
return
}
deliveryServiceRequestComment.ID = id
userErr, sysErr, sc := api.CheckIfUnModified(r.Header, inf.Tx, id, "deliveryservice_request_comment")
if userErr != nil || sysErr != nil {
api.HandleErr(w, r, tx, sc, userErr, sysErr)
Expand Down
Loading