fix: correct API key prefix config key inconsistency#24336
fix: correct API key prefix config key inconsistency#24336ascender1729 wants to merge 1 commit intocalcom:mainfrom
Conversation
…eyPrefix Fixes calcom#23683 This fixes a critical authentication bug where API key validation was failing with 401 Unauthorized errors. Root Cause: The configuration file (apps/api/v2/src/config/app.ts) defines the API key prefix as api.keyPrefix, but multiple authentication files were incorrectly referencing api.apiKeyPrefix. When config.get("api.apiKeyPrefix") was called, it returned undefined, causing the code to fall back to the default "cal_" prefix. However, if a custom API_KEY_PREFIX environment variable was configured, this inconsistency between the check and strip operations would cause: 1. API key detection to use default "cal_" prefix 2. API key stripping to use the actual configured prefix 3. Mismatched hash computation 4. Database lookup failure 5. 401 Unauthorized error Changes: - Updated api-auth.strategy.ts (2 occurrences) - Updated bookings.controller.ts for 2024-04-15 API - Updated input.service.ts for 2024-08-13 API - Updated permissions.guard.ts - Updated permissions.guard.spec.ts test file All now correctly use api.keyPrefix to match the configuration schema. Impact: Resolves 401 errors for Elevenlabs integration and all other API users attempting to use the /v2/bookings endpoint with API keys.
|
@ascender1729 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis change replaces the configuration key used to read the API key prefix from api.apiKeyPrefix to api.keyPrefix across API-key authentication paths. Updates occur in bookings.controller.ts (owner ID resolution), input.service.ts (API key stripping/hashing and OAuth fallback), permissions.guard.ts and its spec (config lookup), and api-auth.strategy.ts (bearer token classification). The logic for detecting API keys via isApiKey, stripping the prefix, and proceeding with existing control flow remains unchanged. In permissions.guard.ts, the prefix defaults to "cal_". Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (5)
🧰 Additional context used📓 Path-based instructions (4)**/*.ts📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Files:
**/*.{ts,tsx,js,jsx}⚙️ CodeRabbit configuration file
Files:
**/*.{service,repository}.ts📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Files:
🧬 Code graph analysis (4)apps/api/v2/src/ee/bookings/2024-08-13/services/input.service.ts (1)
apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts (1)
apps/api/v2/src/modules/auth/guards/permissions/permissions.guard.ts (1)
apps/api/v2/src/modules/auth/strategies/api-auth/api-auth.strategy.ts (1)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@ascender1729 add a before and after result |
Until then marking it as draft |
|
This PR is being marked as stale due to inactivity. |
|
This PR has been closed due to inactivity. Please feel free to reopen it if you'd like to continue the work. |
Summary
Fixes #23683 - Resolves 401 Unauthorized errors when using API keys with the
/v2/bookingsendpoint.This PR fixes a critical configuration key inconsistency that was causing API key authentication failures, particularly affecting the Elevenlabs integration and all other API users.
Root Cause
The configuration file (
apps/api/v2/src/config/app.ts) defines the API key prefix asapi.keyPrefix, but multiple authentication files were incorrectly referencingapi.apiKeyPrefix(a non-existent config key).When
config.get("api.apiKeyPrefix")was called, it returnedundefined, causing the code to fall back to the hardcoded default"cal_". While this works for the default case, it creates a critical inconsistency:config.get("api.apiKeyPrefix")→ returnsundefined→ falls back to"cal_"config.get("api.keyPrefix")→ returns the actual configured value (e.g., custom prefix fromAPI_KEY_PREFIXenv var)Changes
Updated all occurrences from
api.apiKeyPrefixtoapi.keyPrefixin:apps/api/v2/src/modules/auth/strategies/api-auth/api-auth.strategy.ts(2 occurrences)apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts(1 occurrence)apps/api/v2/src/ee/bookings/2024-08-13/services/input.service.ts(1 occurrence)apps/api/v2/src/modules/auth/guards/permissions/permissions.guard.ts(1 occurrence)apps/api/v2/src/modules/auth/guards/permissions/permissions.guard.spec.ts(1 test occurrence)Total: 5 files changed, 6 insertions(+), 6 deletions(-)
Test Plan
api.apiKeyPrefixhave been replaced withapi.keyPrefixapps/api/v2/src/config/app.tsline 18yarn installto resolve workspace dependenciesImpact
Evidence
From issue #23683:
/v2/slotsendpoint worked with their API key/v2/bookingswith 401 errorRelated: #23683