Skip to content

fix: move Web3.Storage keys to server-side only#1791

Closed
Ai-chan-0411 wants to merge 1 commit intoMetaFam:developfrom
Ai-chan-0411:fix/web3-storage-key-exposure-1750
Closed

fix: move Web3.Storage keys to server-side only#1791
Ai-chan-0411 wants to merge 1 commit intoMetaFam:developfrom
Ai-chan-0411:fix/web3-storage-key-exposure-1750

Conversation

@Ai-chan-0411
Copy link
Copy Markdown

Fixes #1750

Problem

Web3.Storage access key (NEXT_PUBLIC_WEB3_STORAGE_KEY) and proof (NEXT_PUBLIC_WEB3_STORAGE_PROOF) are exposed to the client because they use the NEXT_PUBLIC_ prefix. This means the private signing key is visible in the browser's source code.

Solution

  • Remove NEXT_PUBLIC_ prefix from WEB3_STORAGE_KEY, WEB3_STORAGE_TOKEN, and WEB3_STORAGE_PROOF so they are only available server-side
  • Create a proper API route (POST /api/w3up-delegate) that handles delegation server-side and returns a serialized delegation to the client
  • Update useW3upClient hook to fetch the delegation via HTTP request instead of directly importing server-side code
  • Keep NEXT_PUBLIC_WEB3_STORAGE_DID as public since DIDs are not secrets

Migration

After merging, update your .env file:

# Before
NEXT_PUBLIC_WEB3_STORAGE_KEY=...
NEXT_PUBLIC_WEB3_STORAGE_TOKEN=...
NEXT_PUBLIC_WEB3_STORAGE_PROOF=...

# After
WEB3_STORAGE_KEY=...
WEB3_STORAGE_TOKEN=...
WEB3_STORAGE_PROOF=...

/attempt 1750

- Remove NEXT_PUBLIC_ prefix from WEB3_STORAGE_KEY and WEB3_STORAGE_PROOF
  to prevent them from being bundled into client-side JavaScript
- Replace direct import of delegation logic with proper Next.js API route
  (POST /api/w3up-delegate) that runs server-side only
- Update useW3upClient hook to fetch delegation via HTTP instead of
  direct function import
- Remove web3StorageToken and web3StorageKey from client-accessible config
- Keep web3StorageDID as NEXT_PUBLIC_ since DIDs are not secrets
@codesandbox
Copy link
Copy Markdown

codesandbox bot commented Apr 11, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

@aoi-dev-0411 is attempting to deploy a commit to the MetaFamily Team on Vercel.

A member of the Team first needs to authorize it.

@Ai-chan-0411
Copy link
Copy Markdown
Author

Closing due to no review activity. Thank you for the opportunity!

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.

Web3.Storage Access Key Is Published To The Client

1 participant