Skip to content

[service-utils] Improve 403 error messages with team and project details #7114

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

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 21, 2025


PR-Codex overview

This PR focuses on improving error messages for 403 responses in the service-utils package, providing more context in the messages related to unauthorized services and actions.

Detailed summary

  • Updated error messages in service.test.ts to use toContain for better matching.
  • Enhanced error messages in service.ts to include team and project details for unauthorized service and action responses.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages for authorization failures, providing more detailed information about the team or project involved when access is denied. This helps users better understand the context of HTTP 403 Forbidden responses.

Copy link

changeset-bot bot commented May 21, 2025

🦋 Changeset detected

Latest commit: 60037fb

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

This PR includes changesets to release 1 package
Name Type
@thirdweb-dev/service-utils 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

Copy link

coderabbitai bot commented May 21, 2025

Walkthrough

The changes introduce more descriptive error messages in the authorizeService function, providing specific context about the team or project involved in authorization failures. Additionally, a new changeset file documents a patch version update for the @thirdweb-dev/service-utils package, reflecting the improved error messaging for HTTP 403 responses. Test assertions were updated to check error message substrings instead of exact matches.

Changes

File(s) Change Summary
packages/service-utils/src/core/authorize/service.ts Enhanced error messages in authorizeService to include team/project names and identifiers on authorization failure.
packages/service-utils/src/core/authorize/service.test.ts Updated test assertions to check for substring containment in error messages instead of exact string matches.
.changeset/blue-mice-prove.md Added changeset documenting a patch version update for improved HTTP 403 error messages in @thirdweb-dev/service-utils.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant authorizeService
    participant Team/Project Data

    Client->>authorizeService: Request authorization
    authorizeService->>Team/Project Data: Retrieve team/project info
    Team/Project Data-->>authorizeService: Return team/project info
    alt Unauthorized for team
        authorizeService-->>Client: Return error with team name and ID
    else Unauthorized for project
        authorizeService-->>Client: Return error with project name and publishable key
    else Unauthorized action for project
        authorizeService-->>Client: Return error with project name and publishable key
    else Authorized
        authorizeService-->>Client: Grant access
    end
Loading

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9db36d3 and 60037fb.

📒 Files selected for processing (3)
  • .changeset/blue-mice-prove.md (1 hunks)
  • packages/service-utils/src/core/authorize/service.test.ts (2 hunks)
  • packages/service-utils/src/core/authorize/service.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/blue-mice-prove.md
  • packages/service-utils/src/core/authorize/service.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Unit Tests
  • GitHub Check: Build Packages
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Lint Packages
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/service-utils/src/core/authorize/service.test.ts (2)

34-36: Good adaptation to support enhanced error messages

The change from toBe() to toContain() properly accommodates the improved error messages that now include additional team and project details while still ensuring the core error message is present.


55-57: Appropriate test assertion update

Switching from exact matching to substring matching correctly handles the enhanced error messages that now include more contextual details about unauthorized actions while maintaining backward compatibility with the core message content.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented May 21, 2025

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

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 7:22pm
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 7:22pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 7:22pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 7:22pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 7:22pm

@joaquim-verges joaquim-verges marked this pull request as ready for review May 21, 2025 18:16
@joaquim-verges joaquim-verges requested a review from a team as a code owner May 21, 2025 18:16
Copy link
Member Author

joaquim-verges commented May 21, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/service-utils/src/core/authorize/service.ts (1)

59-59: Fix extra spacing before URL
There's an accidental double space before the URL in the action-unauthorized message. It should be a single space.
Apply this diff:

- ... dashboard:  https://thirdweb.com/create-api-key
+ ... dashboard: https://thirdweb.com/create-api-key
.changeset/blue-mice-prove.md (1)

1-5: Enhance changeset summary specificity
The summary “Better error messages for 403 responses” is correct but could include key details for clearer release notes. For example:

Include team name/ID and project name/publishable key in 403 Forbidden error messages
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72cc27a and 9db36d3.

📒 Files selected for processing (2)
  • .changeset/blue-mice-prove.md (1 hunks)
  • packages/service-utils/src/core/authorize/service.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/service-utils/src/core/authorize/service.ts (2)

22-22: Confirm PII exposure for team context
Including team.name and team.id in the client-facing error message may expose internal identifiers. Please verify that this aligns with our PII/security policy and is safe to expose in logs or to end users.


45-45: Confirm PII exposure for project context
The error message now includes project.name and project.publishableKey. Ensure that surfacing the publishable key and project name in a 403 error does not violate any security guidelines or leak sensitive details.

Copy link
Contributor

github-actions bot commented May 21, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 56.57 KB (0%) 1.2 s (0%) 169 ms (+144.02% 🔺) 1.3 s
thirdweb (cjs) 309.52 KB (0%) 6.2 s (0%) 587 ms (+4.18% 🔺) 6.8 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 65 ms (+1230.16% 🔺) 179 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 16 ms (+900.43% 🔺) 27 ms
thirdweb/react (minimal + tree-shaking) 19.5 KB (0%) 390 ms (0%) 71 ms (+428.38% 🔺) 461 ms

Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.60%. Comparing base (72cc27a) to head (60037fb).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7114   +/-   ##
=======================================
  Coverage   55.60%   55.60%           
=======================================
  Files         901      901           
  Lines       58121    58121           
  Branches     4067     4067           
=======================================
  Hits        32320    32320           
  Misses      25696    25696           
  Partials      105      105           
Flag Coverage Δ
packages 55.60% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges merged commit 4b9a506 into main May 21, 2025
25 checks passed
@joaquim-verges joaquim-verges deleted the _service-utils_Improve_403_error_messages_with_team_and_project_details branch May 21, 2025 21:07
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.

1 participant