-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(remix): Use domains to prevent scope bleed #5570
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
411c607
add route id to remix spans
AbhiPrasad 9b2e0aa
fix tests
AbhiPrasad 77b682c
fix(remix): Use domains to prevent scope bleed
AbhiPrasad 760b833
add scope bleed test
AbhiPrasad 0b4eef6
switch to use domain.bind
AbhiPrasad d4b8f64
Update packages/remix/test/integration/app/routes/scope-bleed/$id.tsx
AbhiPrasad db365af
Update packages/remix/test/integration/app/routes/scope-bleed/$id.tsx
AbhiPrasad 1e31dcb
Merge branch 'master' into abhi-remix-scope-bleed
AbhiPrasad 8d01153
Merge branch 'master' into abhi-remix-scope-bleed
AbhiPrasad f7e4a89
domain on express as well
AbhiPrasad 9945932
introduce timing
AbhiPrasad f92c512
clean up timing algo
AbhiPrasad cde925b
clean up timing
AbhiPrasad 51391c4
set timeout in test body
AbhiPrasad d2d989c
plz dont be flaky
AbhiPrasad 58315e4
transaction not undefined
AbhiPrasad 4b6f920
actually introduce random numbers
AbhiPrasad 34f9c6d
shorten timestamps
AbhiPrasad 6610038
Merge branch 'master' into abhi-remix-scope-bleed
AbhiPrasad 8d707e0
fix test - but not the fix
AbhiPrasad 51e5c0f
changes to make this work
AbhiPrasad af26181
remove logger
AbhiPrasad 464904f
flush events in res.end
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
packages/remix/test/integration/app/routes/scope-bleed/$id.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { json, LoaderFunction } from '@remix-run/node'; | ||
|
||
import * as Sentry from '@sentry/remix'; | ||
|
||
export const loader: LoaderFunction = async ({ params: { id } }) => { | ||
const timeTil = parseInt(id || '', 10) * 1000; | ||
await new Promise(resolve => setTimeout(resolve, 3000 - timeTil)); | ||
Sentry.setTag(`tag${id}`, id); | ||
return json({ test: 'test' }); | ||
}; | ||
|
||
export default function ScopeBleed() { | ||
return ( | ||
<div> | ||
<h1>Hello</h1> | ||
</div> | ||
); | ||
} |
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
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.
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.
Did this test previously fail? IOW, would it actually detect scope bleed if we were to accidentally re-introduce it?
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.
This test did previously fail - but now it seems to be sometimes passing 🤔, worried it's a flaky test then. @lobsterkatie any ideas for a good test against scope bleed?
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.
Hmmm... I would assume we basically have to force them to be simultaneous, right? This test would pass regardless, as long as there were only one request/transaction at at time, so maybe the flakiness is coming from the requests just getting through so quickly that they end up being sequential. Could you introduce a variable delay into each request, and set them off at a set interval, to guarantee they'd all be in flight at the same time? I'm picturing something like (assuming 5 requests):
Request 1: Starts at timestamp 0, waits 5 seconds to set its tag, waits another second, finishes
Request 2: Starts at timestamp 1 second, waits 4 seconds to set its tag, waits another second, finishes
...
Request 5: Starts at timestamp 4 seconds, waits 1 second to set its tag, waits another second, finishes
That way, you know that 5 seconds in, all five requests should be trying to set their tags more or less at the same moment, and should also all be finishing at more or less the same time (meaning they'd all be trying to grab scope data to attach to the event roughly simultaneously).
(You might also consider introducing a tiny bit of randomness (wait anywhere between 0.99 and 1.01 seconds to start each request, and the do it again for finishing, for example), just so that the order in which requests set and get their tags is mixed up.)
If everything still comes through cleanly, then I think we'd've proved the point, right?
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.
Yup, and we've tested on express as well. Thanks Katie, used a simple version of your logic here.
I tried the randomness, but it wasn't working that well, so elected to do this.