Added character validation to /api/fleet/orbit/device_token endpoint (#19919)

https://github.com/fleetdm/confidential/issues/6978
Added character validation to /api/fleet/orbit/device_token endpoint

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Victor Lyuboslavsky 2024-06-21 08:43:08 -05:00 committed by GitHub
parent 8d064065d7
commit 0dd620e61b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View file

@ -0,0 +1 @@
Added character validation to /api/fleet/orbit/device_token endpoint

View file

@ -11187,6 +11187,13 @@ func (s *integrationTestSuite) TestHostDeviceToken() {
}
s.DoJSON("POST", "/api/fleet/orbit/device_token", body, http.StatusBadRequest, &response{})
// Use illegal characters
body = setOrUpdateDeviceTokenRequest{
OrbitNodeKey: *orbitHost.OrbitNodeKey,
DeviceAuthToken: "../.",
}
s.DoJSON("POST", "/api/fleet/orbit/device_token", body, http.StatusBadRequest, &response{})
// Write bad node key
body = setOrUpdateDeviceTokenRequest{
OrbitNodeKey: "",

View file

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"github.com/fleetdm/fleet/v4/server"
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
@ -490,6 +491,10 @@ func (svc *Service) SetOrUpdateDeviceAuthToken(ctx context.Context, deviceAuthTo
return badRequest("device auth token cannot be empty")
}
if url.QueryEscape(deviceAuthToken) != deviceAuthToken {
return badRequest("device auth token contains invalid characters")
}
host, ok := hostctx.FromContext(ctx)
if !ok {
return newOsqueryError("internal error: missing host from request context")