AudiusProject / audius-protocol

The Audius Protocol - Freedom to share, monetize, and listen to any audio content.
https://docs.audius.org
Other
552 stars 106 forks source link

[PAY-3388] Migrate /feed to SDK #9950

Open schottra opened 1 day ago

schottra commented 1 day ago

Description

This is an updated version of #9593 . Now that SDK can load and make requests before libs has finished initializing, we can re-enable the migrated feed endpoint. There was an additional change necessary for web to remove a waitForLibsInit from the SDK initialization function. It was meant to prevent apiClient from making requests too soon. But we've now removed all but one request from apiClient and it's unlikely (not possible?) for it to be called during app initialization.

BONUS FIX: There was a strange concurrency issue with logging in < 60 seconds after loading the page where a race condition would cause us to think that the previously cached SDK request signature was still valid. This was due to the fact that many requests could be in the check/update flow simultaneously and flip the "current address" and signature value back and forth such that we end up with a signature that wasn't actually generated by the current wallet but remains cached for the next 60 seconds. This would cause the feed to fail to load with a 401 since the generated wallet we use while signed out won't map to a user. It would also apply to any other requests which require a signature (chats, notifications, etc) for 60 seconds after login.

Yikes.

The fix was to use a promise to gate checking/updating of the value to a single instance at a time, with all queued requests afterwards just reading the result.

How Has This Been Tested?

Tested locally against staging and on a prod subdomain. The time to make the initial /feed request did not differ significantly from current prod. (1.25-3 seconds depending on initial page load time)

changeset-bot[bot] commented 1 day ago

🦋 Changeset detected

Latest commit: c6846916530578302515d682051fae9b3f7a2832

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ------------------ | ----- | | @audius/sdk | Patch | | @audius/sp-actions | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

gitguardian[bot] commented 1 day ago

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | | | -------------- | ------------------ | ------------------------------ | ---------------- | --------------- | -------------------- | | [11648676](https://dashboard.gitguardian.com/workspace/27667/incidents/11648676?occurrence=166851136) | Triggered | Generic High Entropy Secret | 97d2b31df280ce56fc1816f16bfa634f50dd400b | core/infra/dev_config/sandbox-one.env | [View secret](https://github.com/AudiusProject/audius-protocol/commit/97d2b31df280ce56fc1816f16bfa634f50dd400b#diff-c614183499e073124bfbebffea189db90334ad35efefe869390a5d716aede0baL2) |
🛠 Guidelines to remediate hardcoded secrets
1. Understand the implications of revoking this secret by investigating where it is used in your code. 2. Replace and store your secret safely. [Learn here](https://blog.gitguardian.com/secrets-api-management?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) the best practices. 3. Revoke and [rotate this secret](https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/generic_high_entropy_secret#revoke-the-secret?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). 4. If possible, [rewrite git history](https://blog.gitguardian.com/rewriting-git-history-cheatsheet?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data. To avoid such incidents in the future consider - following these [best practices](https://blog.gitguardian.com/secrets-api-management/?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) for managing and storing secrets including API keys and other credentials - install [secret detection on pre-commit](https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) to catch secret before it leaves your machine and ease remediation.

🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

audius-infra commented 1 day ago

Preview this change https://demo.audius.co/pay-3388-implement-client-v1-feed