pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
4.13k stars 305 forks source link

chore: use plain app id in key gen #960

Open juliusmarminge opened 2 weeks ago

juliusmarminge commented 2 weeks ago

We decided it was too hard to port the encoding to other languages so we now do a prefix check on appId in plain text instead of the encoded value.

ref: https://github.com/pingdotgg/uploadthing-infra/pull/550

Summary by CodeRabbit

vercel[bot] commented 2 weeks ago

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

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 18, 2024 6:17pm
1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **legacy-docs-uploadthing** | ⬜️ Ignored ([Inspect](https://vercel.com/pinglabs/legacy-docs-uploadthing/GUa9a3bBi5mStNf1PEbS8pWo8SER)) | [Visit Preview](https://legacy-docs-uploadthing-git-plain-app-id-pinglabs.vercel.app) | | Sep 18, 2024 6:17pm |
changeset-bot[bot] commented 2 weeks ago

⚠️ No Changeset found

Latest commit: b281a5c7d9c7d2c09c6b57658556e012ddd46535

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

coderabbitai[bot] commented 2 weeks ago

Walkthrough

The changes primarily involve the simplification of the file key generation process. The previous implementation utilized the Sqids library for encoding and randomization, while the new approach directly concatenates the appId with a user-defined file seed. The updated requirements for the file seed ensure it is unique, URL-safe, and at least 36 characters long, streamlining the overall key generation without the need for additional complexity.

Changes

File Path Change Summary
docs/src/app/(docs)/uploading-files/page.mdx, packages/shared/src/crypto.ts The generateKey function was modified to simplify the key generation process by removing the encoding of appId and directly concatenating it with the encodedFileSeed. The new implementation eliminates the use of the Sqids library and focuses on ensuring the file seed is URL-safe. The verifyKey function was also removed, affecting key verification.

Poem

In the meadow where the keys align,
A rabbit hops, feeling just fine.
With seeds so safe and bright,
The keys now shine, a pure delight!
No more shuffle, just a simple way,
To share our files and play all day! 🐇✨


Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 75c1da4a5a76eda4d17cdf82b5564c19ea0fd9ca and b281a5c7d9c7d2c09c6b57658556e012ddd46535.
Files selected for processing (1) * packages/shared/src/crypto.ts (1 hunks)
Additional comments not posted (1)
packages/shared/src/crypto.ts (1)
`112-112`: **Carefully assess the impact of the change in key generation format.** The change in the `generateKey` function, which now directly concatenates `appId` and `encodedFileSeed` without encoding `appId`, could have significant implications: 1. Compatibility issues: The change in key format could lead to compatibility issues with existing systems or databases that rely on the previous format. Ensure that this change is thoroughly tested and validated against all dependent systems. 2. Security and integrity: The removal of the `verifyKey` function indicates that there is no longer a mechanism to validate the relationship between the key and the `appId`. This could have implications for security and integrity checks in the system. Consider implementing an alternative verification mechanism if necessary. 3. Key uniqueness and security: Using the raw `appId` instead of the encoded version may affect the uniqueness and security properties of the generated keys. Assess whether the new key format maintains the required level of uniqueness and security. Consider adding tests to validate these properties. To ensure system stability and compatibility, please: - Review and update any key format validation logic in the codebase. - Modify existing tests to account for the new key format. - Add new tests to verify the compatibility of the new key format with all dependent systems. - Perform integration testing to ensure that URL generation and API calls work correctly with the new key format. Run the following script to verify the usage of the `generateKey` function and its return value across the codebase:
Verification successful --- **Verification confirms removal of `verifyKey` function and potential compatibility.** Based on the verification results: 1. The `verifyKey` function has indeed been removed from the codebase, confirming the change mentioned in the original review comment. 2. No direct key format validations or comparisons were found, suggesting that the system may not rely on a specific key format for validation. This could reduce the impact of the format change. 3. Key-related types and interfaces (found in `packages/uploadthing/src/sdk/types.ts`) appear to be focused on file operations rather than the internal structure of the key itself. This suggests that the change in key format may not significantly impact these types. 4. The `generateKey` function is used in test files and the SDK, but its usage doesn't seem to depend on the internal structure of the key. Given these findings: - The removal of the `verifyKey` function and the change in key generation format appear to be intentional changes that don't severely impact the existing codebase. - The lack of key format validations and the nature of key-related types suggest that the system may be more resilient to the key format change than initially thought. However, to ensure system stability: 1. Update any remaining tests that still use the `verifyKey` function. 2. Review the `generateSignedURL` function (which wasn't found in our search) to ensure it's compatible with the new key format. 3. Perform thorough integration testing, especially for API calls using the `utapi` object, to verify that the new key format works as expected in all scenarios.
Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify the usage of the `generateKey` function and its return value. # Test 1: Search for the function usage and its return value usage rg --type ts -A 10 'const key = .*generateKey' # Test 2: Search for any key format validations or comparisons rg --type ts 'key\.match|key\.startsWith|key\.endsWith|key\.includes' # Test 3: Look for any database operations or API calls using the key rg --type ts 'db\..*\(.*key|api\..*\(.*key' ``` Length of output: 6681 --- Script: ```shell #!/bin/bash # Description: Further investigation of key-related functions and types # Check for the current state of the verifyKey function rg --type ts 'function verifyKey' # Look for key-related type definitions or interfaces rg --type ts 'type.*Key|interface.*Key' # Investigate the generateSignedURL function rg --type ts -A 10 'function generateSignedURL' # Check for configuration files or environment variables related to key generation rg --type ts 'process\.env\..*KEY|config\..*key' ``` Length of output: 1717
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: -- `I pushed a fix in commit , please review it.` -- `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: -- `@coderabbitai generate unit testing code for this file.` -- `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: -- `@coderabbitai generate interesting stats about this repository and render them as a table.` -- `@coderabbitai read src/utils.ts and generate unit testing code.` -- `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` -- `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
pkg-pr-new[bot] commented 2 weeks ago

Open in Stackblitz

More templates

- [@example/minimal-appdir](https://pkg.pr.new/template/b1fcada7-f0e9-4365-abe3-37f4ac92c567) - [@example/minimal-astro-react](https://pkg.pr.new/template/1c74378e-7a49-42dd-bde4-ed5009826662) - [@example/minimal-expo](https://pkg.pr.new/template/14940cf1-601d-4a2a-b077-caa17e214b04) - [@example/minimal-nuxt](https://pkg.pr.new/template/efc4029f-2393-4247-853b-8bec323c4b19) - [@example/minimal-pagedir](https://pkg.pr.new/template/2f97fe8a-ef86-4320-b762-e4010c63c673) - [@example/minimal-solidstart](https://pkg.pr.new/template/9230d1c3-befd-4706-84a5-e2a118393031) - [@example/minimal-sveltekit](https://pkg.pr.new/template/29e19a7d-c9ea-4916-98de-72c2952a5142)

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/shared@960

commit: b281a5c

github-actions[bot] commented 2 weeks ago

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 26.03KB No treemap on forks
PR (e3e14f676b8b62d4cc995e07136378917be02517) 26.03KB No treemap on forks
Diff No change