Skip to content

fix: cross-origin fetch noise, bytes.Reader race, and form decoding fallback#130

Open
eideroliveira wants to merge 1 commit into
qor5:masterfrom
eideroliveira:pr/fix-fetch-interceptor-and-race
Open

fix: cross-origin fetch noise, bytes.Reader race, and form decoding fallback#130
eideroliveira wants to merge 1 commit into
qor5:masterfrom
eideroliveira:pr/fix-fetch-interceptor-and-race

Conversation

@eideroliveira
Copy link
Copy Markdown

Summary

Three independent bugfixes discovered while running go-plaid in production:

  • fetchInterceptor: Skip cross-origin requests (e.g. Google Analytics) entirely — we have no insight into them and forcing a JSON parse on their bodies just produces console noise. Also swallow JSON parse errors on same-origin responses gracefully: a non-JSON body is not an error, only the request lifecycle matters.

  • builder.PacksHandler: Create a new bytes.Reader per request to avoid a data race — http.ServeContent mutates the reader's seek offset, so concurrent requests sharing the same reader corrupt each other.

  • api.UnmarshalForm: Fall back to r.Form when MultipartForm is nil so that URL-encoded POST bodies are decoded correctly.

Test plan

  • Verified cross-origin fetch requests (Google Analytics, third-party scripts) no longer produce JSON parse errors in the console
  • Verified concurrent requests to packed JS/CSS assets serve correct content without corruption
  • Verified URL-encoded form submissions decode correctly when not using multipart encoding

…allback

fetchInterceptor: skip cross-origin requests (e.g. Google Analytics) entirely
— we have no insight into them and forcing a JSON parse on their bodies just
produces console noise. Also swallow JSON parse errors on same-origin
responses: a non-JSON body is not an error, only the request lifecycle matters.

builder: create a new bytes.Reader per request in PacksHandler to avoid a
data race when concurrent requests share the same reader (its seek offset
is mutated by http.ServeContent).

api: fall back to r.Form when MultipartForm is nil so that URL-encoded POST
bodies are decoded correctly.
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.

1 participant