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: move buildStorageKeySuffix function to common and bump release #207

Merged

Conversation

typotter
Copy link
Collaborator


labels: mergeable

Fixes: FF-3920

Motivation and Context

This method is used by both react-native and js-client SDKs so rather than duplicate, we'll move it to common. Also, this moves the algorithm to use a hash instead of just slicing the API key to avoid leaking sensitive info. This also makes suffix collisions much less likely

*/
export function buildStorageKeySuffix(apiKey: string): string {
// Note that we hash the API key and use the last 16 characters of the digest.
return new SparkMD5().append(apiKey).end().slice(-16);
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check for bounds here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we're hashing, taking the first or last characters will be sufficiently entropic.
Changed the slice call here to take the first 16 characters. slice is resilient to parameters larger than the length of the sting.

@typotter typotter merged commit 047d322 into main Jan 31, 2025
8 checks passed
@typotter typotter deleted the typo/ff-3920-js-common-sdk-move-buildstoragekeysuffix-to-common branch January 31, 2025 19:07
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.

2 participants