fix(dev-server): inject service role token for unauthenticated function calls#516
Conversation
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.52-pr.516.3d325cbPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.52-pr.516.3d325cb"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.52-pr.516.3d325cb"
}
}
Preview published to npm registry — try new features instantly! |
| // unauthenticated callers (e.g. public-facing subscribe forms). | ||
| proxyReq.setHeader( | ||
| "Base44-Service-Authorization", | ||
| authorization ?? "Bearer base44-dev-service-token", |
There was a problem hiding this comment.
This is not robust enough even for dev.
authorization is user authorization. It means that in case user is logged in locally with newly created user (also locally), then overall permissions will be limited. Which is not expected for server side authorization.
I think approach should be more robust than that.
I think Base44-Service-Authorization should be actual JWT, maybe simple solution will be to create token with email like server@server.com and then in the code check if email is "server" then allow everything. something like that
There was a problem hiding this comment.
Same goes for Bearer base44-dev-service-token - this token will fail for code that relies on user being presented in JWT:
55f4cdc to
b24046f
Compare
…on calls The function router only forwarded Base44-Service-Authorization when a user Authorization header was present. Public-facing functions (e.g. a subscribe form) are called without user auth, so asServiceRole threw "Service token is required" before making any HTTP request. In production, Base44 always injects the service role token when forwarding requests to functions. Mirror that behaviour in the dev server by defaulting to a synthetic dev token when no user auth header exists. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ated calls Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This reverts commit dabbb52.
5927473 to
33ab553
Compare
Note
Description
Fixes service-role authorization in the local dev server so
asServiceRoleworks the same way it does in production. Previously the dev server only forwarded the callers ownauthorizationheader to functions, so unauthenticated callers (e.g. public-facing subscribe forms) could not perform privileged service-role operations. The dev server now always mints and injects a service-role JWT, and the RLS/FLS engine recognizes the service principal and bypasses access rules accordingly.Related Issue
None
Type of Change
Changes Made
auth/tokens.tscentralizing JWT minting:createJwtToken,createServiceAuthorizationHeader,SERVICE_ROLE_EMAIL(server@server.com), andisServiceSubject.routes/functions.ts) now always injects a freshly-mintedBase44-Service-Authorizationservice token instead of only forwarding the callersauthorizationheader, mirroring production behavior soasServiceRoleworks for unauthenticated callers.resolveCurrentUser(routes/entities/current-user.ts) resolves the service-role JWT subject to a synthetic adminSERVICE_USERwithis_service: true.db/rls.ts) short-circuits to allow whenuser.is_service === true; FLS now treats onlyundefinedrules (not all falsy rules) as "no rule", so explicitfalsecorrectly denies normal users while service users bypass it.entities-router.ts) let service users bypass an explicitfalsedelete RLS rule, and align read filtering on!== undefined.auth-router.tsto import the sharedcreateJwtTokeninstead of defining its own, removing the duplicatedLOCAL_DEV_SECRET.cli/index.ts(lint fix).Testing
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
Added
tests/cli/dev-rls.spec.tscovering service-user RLS/FLS bypass, and expandedtests/cli/dev.spec.tswith coverage for service-token injection on unauthenticated function calls. The service-role token is local-only and signed with the devLOCAL_DEV_SECRET.🤖 Generated by Claude | 2026-06-04 08:53 UTC | 3d325cb