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

feat: default session id in frontend api #5083

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Oct 18, 2023

About the changes

What problem are we solving?

  • enabled info and variant info in the same feature have to be consistent when stickiness is set to default
  • also we want to have consistency between parent and child features

Solution:

  • if the user didn't provide sessionId, generate one one the fly

Important files

Discussion points

Is Math.random() good enough?

@vercel
Copy link

vercel bot commented Oct 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 2:14pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 18, 2023 2:14pm

@@ -74,12 +74,19 @@
const client = await this.clientForProxyToken(token);
const definitions = client.getFeatureToggleDefinitions() || [];

const sessionId = context.sessionId || String(Math.random());

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're not doing cryptography here

.map((feature) => ({
name: feature.name,
enabled: Boolean(feature.enabled),
variant: client.forceGetVariant(feature.name, context),
variant: client.getVariant(feature.name, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't have to use forceGetVariant anymore. Since we have sessionId we don't have to care how getVariant is implemented locally.

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Oh awesome! This LGTM

Guessing a test is borderline impossible here? I think that's okay, this is simple enough

@kwasniew
Copy link
Contributor Author

@sighphyre I can think of a property based test or run a regular test 50 times and verify some properties. It will be more work than the change itself but maybe it's worth the effort.

@sighphyre
Copy link
Member

@sighphyre I can think of a property based test or run a regular test 50 times and verify some properties. It will be more work than the change itself but maybe it's worth the effort.

Yeah, it may be a lot of work. I also think it may be worth it. A prop test would be awesome. We've done some "run this 10K times and poke at the statistics" tests before, they have been useful but they have drawbacks

Either way, I'm not going to block this for not having one of those. I still think LGTM, I'll leave it up to you if you want to that now, later or never

@kwasniew kwasniew merged commit 1f8d12b into main Oct 18, 2023
9 checks passed
@kwasniew kwasniew deleted the default-session-id-frontend-api branch October 18, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants