feat(https): add enforceAuth option to callable functions#1870
feat(https): add enforceAuth option to callable functions#1870kyungseopk1m wants to merge 1 commit intofirebase:masterfrom
Conversation
Add enforceAuth option to onCall functions, mirroring the existing enforceAppCheck pattern. When set to false, requests with invalid auth tokens log a warning instead of throwing a 401 error. Defaults to true to preserve existing behavior. Fixes firebase#1557
There was a problem hiding this comment.
Code Review
This pull request introduces the enforceAuth option for Firebase HTTPS callable functions in both v1 and v2 SDKs. This feature allows developers to control whether invalid authentication tokens should automatically trigger a 401 Unauthorized response (the default behavior) or be allowed through with a warning, in which case context.auth is expected to be undefined. The changes include updates to configuration interfaces, the request handling logic in wrapOnCallHandler, and new test cases. One piece of feedback suggests explicitly setting context.auth = undefined when an invalid token is permitted to ensure consistency with the documentation and avoid potential issues with mock data in the emulator.
| } else { | ||
| logger.warn( | ||
| "Allowing request with invalid auth token because enforcement is disabled" | ||
| ); | ||
| } |
There was a problem hiding this comment.
To ensure that context.auth is strictly undefined when an invalid token is provided and enforcement is disabled (as stated in the documentation), it should be explicitly cleared. This is particularly important because the emulator hook (lines 803-812) might have already populated context.auth with mock data, which should not be used if an actual (but invalid) token was sent in the request.
} else {
logger.warn(
"Allowing request with invalid auth token because enforcement is disabled"
);
context.auth = undefined;
}There was a problem hiding this comment.
context.auth is already undefined in the INVALID path since checkAuthToken only sets it on success. This matches the existing enforceAppCheck behavior which also does not explicitly reset context.app.
|
Hi @kyungseopk1m thanks for your contribution!! This as a feature is under some internal discussion right now, I'll keep you updated here on the outcome. |
27b147f to
fe714b7
Compare
Description
Fixes #1557
Adds an
enforceAuthoption toonCallcallable functions, mirroringthe existing
enforceAppCheckpattern.Problem:
onCallfunctions unconditionally reject requests withinvalid or expired auth tokens with a 401 error. There is no way to opt
out for public endpoints that don't require authentication.
Solution: Add
enforceAuth?: booleanoption. Whenfalse, requestswith invalid auth tokens log a warning and set
context.authtoundefinedinstead of throwing. Defaults totrueto preserveexisting behavior.
Code sample