-
Notifications
You must be signed in to change notification settings - Fork 140
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
Reduce code paths that could encode post data as the string undefined #300
Conversation
Have shifted to "draft" status for clarity. Am convinced this is (the|a) source of the issue but not convinced I fully understand the consequence of the change yet |
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.
I think it looks good... just one annoying compatibility issue
…rocessed - see #4816
4e61667
to
66e1520
Compare
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.
We talked this over during a pairing session and made a few minor changes.
LGTM!
Property based testing is a mechanism of sending many different combinations of arguments into some software and asserting on the general result of that.
Often when property based testing libraries find possible failures. They search for simpler examples of the failure to make them easy to understand. E.g. A library will try to identify not that failures are caused by "very long strings" but instead that they're caused by "strings longer than 6400 characters"
Imagine someone has implemented an algorithm which should always generate a number below 100
It is easy to see in this simple example that the implementation doesn't meet the spec. But it isn't always easy to see that in real code.
using fast check we could test that the code has the property "regardless of the number given as input it generates a number less than 100"
In this output below we can see FastCheck tried a negative number, identified a failure, and then tried zero to see if that still failed. When it did it reported zero as a counter example to the rule it had been given
In PostHog/posthog#4816 we see many instances of the API receiving an event or screen recording payload where the body is the literal value "undefined"
It is not easy to identify what is causing this
This PR uses property based testing to identify routes through the
encodePostData
method which could cause that outputFast check allows the test below
that property based test identifed a combination that generated the body
data=undefined
if both
options.blob
andoptions.sendBeacon
were false ) and the input was aTypedArray
then the undesirable input was generated.Within the code was the check
Array.isArray
which fails for aTypedArray
(thanks, JavaScript) and as a result the code would treat the input as an object and try to read a data property.That can now be made impossible
NB that doesn't mean that the running application does travel that code path but that the code path was present and could have been travelled