Skip to content

fix: authorize front-end RPC calls with the Prividium session token - #656

Merged
bxpana merged 6 commits into
mainfrom
fix/prividium-token-total-supply
Aug 27, 2026
Merged

fix: authorize front-end RPC calls with the Prividium session token#656
bxpana merged 6 commits into
mainfrom
fix/prividium-token-total-supply

Conversation

@bxpana

@bxpana bxpana commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What ❔

Attaches the Prividium session token to the front-end's shared JsonRpcProvider, so every RPC call the app makes is authorized as the logged in user.

  • useContext.getL2Provider builds the provider from a FetchRequest carrying Authorization: Bearer <session token> when currentNetwork.prividium is set. Public networks keep passing the bare URL, unchanged.
  • The provider cache now also resets on user change, not just network change, so logging in or out rebuilds it with the right token.
  • useTokenOverview sends the user's address as from, which the Prividium RPC also requires.

Why ❔

Max Total Supply is empty for every token on Prividium chains, reported by Memento (PRIV-185).

The provider was constructed with a bare rpcUrl, so calls reached the permissions API anonymous. checkContractAccess has no anonymous branch, and eth_call is separately rejected when it carries no from, so the call failed twice over before any permission rule was evaluated. No admin-side permission change could have fixed it.

Doing this on the shared provider rather than per call fixes it generically, since the explorer makes other front-end RPC reads that hit the same wall.

With this in place an admin controls visibility from the admin panel by adding totalSupply() to the token's contract or template function permissions and picking who can call it (All Users, or a specific role).

Note on the first commit

The first commit proxied the read through a dedicated explorer API endpoint. Per review that was too narrow, so it is fully reverted in the second commit and the branch diff against main touches only the four app files. The prividium_tokenSupplyDisclosure route was also considered and skipped: DISCLOSURE_METHODS_ENABLED is off in every environment, and it runs a trace plus storage proofs per call to produce a value we would use unverified.

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

The token page reads Max Total Supply with a browser eth_call to totalSupply().
On Prividium that call is anonymous and carries no `from`, so the permissions
API rejects it before any rule is evaluated and the field renders empty for
every token.

Proxy the read through the explorer API instead, which holds the user's
Prividium token in its httpOnly session and can call the RPC as that user with
their address as `from`. Public networks keep calling the contract directly.

Admins then control visibility by adding totalSupply() to the token's contract
or template function permissions.
@bxpana
bxpana requested a review from a team as a code owner August 19, 2026 16:06
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

API E2E Test Results

185 tests   185 ✅  12s ⏱️
 13 suites    0 💤
  1 files      0 ❌

Results for commit 26732f3.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

API Prividium E2E Test Results

9 tests   9 ✅  4s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 26732f3.

♻️ This comment has been updated with latest results.

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR:
https://staging-scan-v2-zksyncos--pr-656-x35s5e2p.web.app

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Unit Test Results

    4 files    281 suites   8m 51s ⏱️
2 317 tests 2 316 ✅ 1 💤 0 ❌
2 484 runs  2 483 ✅ 1 💤 0 ❌

Results for commit 26732f3.

♻️ This comment has been updated with latest results.

Replaces the explorer API proxy endpoint from the previous commit, per review.

Prividium authorizes every RPC call against the caller, but the front-end built its
JsonRpcProvider with a bare URL, so calls went out anonymous and were rejected before
any permission rule was evaluated. The token page's Max Total Supply is the visible
symptom, but this affects any front-end RPC read on a Prividium chain.

Attach the session token to the shared provider so every front-end RPC call is made as
the logged in user, and send the user's address as `from` on the totalSupply read,
which the RPC also requires. Public networks are unaffected.
@bxpana bxpana changed the title fix: read token total supply through the explorer API on Prividium fix: authorize front-end RPC calls with the Prividium session token Aug 19, 2026
@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR:
https://staging-scan-v2-zksyncos--pr-656-x35s5e2p.web.app

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR:
https://staging-scan-v2-zksyncos--pr-656-x35s5e2p.web.app

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR:
https://staging-scan-v2-zksyncos--pr-656-x35s5e2p.web.app

Replaces the localStorage session token from the previous commit, per review.

Prividium authorizes every RPC call against the caller, but the front-end built its
JsonRpcProvider with a bare URL, so calls went out anonymous and were rejected before any
permission rule was evaluated. The token page's Max Total Supply is the visible symptom,
but this affects any front-end RPC read on a Prividium chain.

The browser is not meant to hold the permissions API token, the explorer API session
already does, so add a POST /rpc endpoint that forwards JSON-RPC requests with the
session's token and point the shared provider at it. The RPC infers the caller from the
token, so the `from` workaround on the totalSupply read is no longer needed. Public
networks still talk to the RPC directly.
@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR:
https://staging-scan-v2-zksyncos--pr-656-x35s5e2p.web.app

@wiz-fa2dcc4065

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 1 Medium
Software Management Finding Software Management Findings -
Total 1 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio.

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR:
https://staging-scan-v2-zksyncos--pr-656-x35s5e2p.web.app

@bxpana
bxpana merged commit ffe2b04 into main Aug 27, 2026
23 of 24 checks passed
@bxpana
bxpana deleted the fix/prividium-token-total-supply branch August 27, 2026 19:12
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 3.29.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants