fix: apply withCredentials for sync requests (#168)#195
Open
Hoang130203 wants to merge 1 commit intonaugtur:masterfrom
Open
fix: apply withCredentials for sync requests (#168)#195Hoang130203 wants to merge 1 commit intonaugtur:masterfrom
Hoang130203 wants to merge 1 commit intonaugtur:masterfrom
Conversation
) Previously withCredentials was guarded inside `if(!sync)`, meaning sync requests silently ignored the withCredentials option entirely. The guard was introduced to work around a Firefox crash when withCredentials=true was *always* forced on sync requests. The fix here is to only set withCredentials when the caller explicitly requests it (i.e. options.withCredentials is truthy), which is safe for both sync and async in all modern browsers. Before: xhr.open(method, uri, !sync, ...) if (!sync) { xhr.withCredentials = !!options.withCredentials // sync silently ignored } After: xhr.open(method, uri, !sync, ...) xhr.withCredentials = !!options.withCredentials // applied for all requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #168
withCredentialswas silently ignored for sync requests. The option was set inside anif (!sync)guard:This guard was introduced to work around a Firefox crash when
withCredentialswas always forcedtrueon sync requests — regardless of what the user passed.Root cause distinction
The original crash was caused by unconditionally setting
withCredentials = trueon sync requests. The fix over-corrected by removing it entirely for sync.The real safe behaviour is: only set
withCredentialswhen the caller explicitly opts in. Settingxhr.withCredentials = false(the default whenoptions.withCredentialsis falsy) on a sync request does not trigger the Firefox crash, and setting ittrueonly when the user asks for it is safe in all modern browsers.Fix
Remove the
if (!sync)guard sowithCredentialsis applied consistently for both sync and async requests:This is consistent with how jQuery handles it and matches the behaviour a user would reasonably expect.