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

Don't crash on invalid UTF-8 in headers #22

Merged
merged 2 commits into from
Jun 27, 2022

Conversation

duncanjbrown
Copy link
Contributor

Users are able to craft request content which goes to BigQuery by setting request headers. These can include invalid UTF-8. This can cause issues at the point of job serialization (Sidekiq can't serialize the args) or at the point of sending to BQ (the Google Cloud library can't build the JSON).

We could preemptively roundtrip events to JSON and back again before putting them on the queue, but the Google library expects hashes so we can't reuse that JSON and it's wasteful. Instead, focus on the things we know can be malformed and fix those: ua and referer. We don't need to worry about about query params as Rails will reject those out of hand - see ActionDispatch::Request::Utils.check_param_encoding).

We decided to still send these events, because we send everything, but with � in place of unparseable bytes (which is how String#scrub replaces them).

We were creating on GET and also making pointless events when testing
the queue option. This should be more readable.
Users are able to craft request content which goes to BigQuery by
setting request headers. This can cause issues at the point of job
serialization (Sidekiq can't serialize the args) or at the point of
sending to BQ (the Google Cloud library can't build the JSON), when
there's a string present that's not valid UTF-8.

We could preemptively rountrip events to JSON and back again before
putting them on the queue, but the Google library expects hashes, so we
can't reuse that JSON. Instead, focus on the things we know can be
malformed and fix those: ua, referer and path. We don't need to worry
about query params as Rails will reject these out of hand - see
ActionDispatch::Request::Utils.check_param_encoding).

We decided to still send these requests, because we send everything,
but with � in place of unparseable bytes (which is how String#scrub
replaces them).
Copy link
Contributor

@misaka misaka left a comment

Choose a reason for hiding this comment

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

🚢 💨

@duncanjbrown duncanjbrown merged commit efcb81d into main Jun 27, 2022
@duncanjbrown duncanjbrown deleted the 733-recover-from-malformed-strings-in-user-agents branch June 27, 2022 16:42
@misaka misaka mentioned this pull request Jun 28, 2022
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