Skip to content

Commit 30d5496

Browse files
committed
refactor(auth): correct a drifted docstring and two cache nits
- `getSessionPolicy`'s docstring still said the CREATE hook allows the sign-in on a failed read. It has refused when the governing org is known since the fail-closed split; say so. - `SECURITY_POLICY_VERSION_CACHE_TTL_MS` had no consumer outside this module, and exporting one of the two sibling TTLs but not the other was arbitrary. - Pass an explicit `ttl` for both membership outcomes instead of relying on `undefined` to mean the constructor default, so the positive/negative asymmetry is visible at the call site.
1 parent b9d8047 commit 30d5496

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

apps/sim/lib/auth/security-policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const logger = createLogger('SecurityPolicy')
2121
* never cached; it is read fresh at enforcement time (see `session-policy.ts`),
2222
* which is what keeps a stale version from ever pairing with a stale policy.
2323
*/
24-
export const SECURITY_POLICY_VERSION_CACHE_TTL_MS = 60 * 1000
24+
const SECURITY_POLICY_VERSION_CACHE_TTL_MS = 60 * 1000
2525
const SECURITY_POLICY_VERSION_CACHE_MAX_ENTRIES = 5_000
2626

2727
const MEMBERSHIP_CACHE_TTL_MS = 60 * 1000
@@ -155,7 +155,7 @@ export async function getMemberOrganizationId(
155155
membershipCache.set(
156156
userId,
157157
{ organizationId },
158-
organizationId ? undefined : { ttl: NEGATIVE_MEMBERSHIP_CACHE_TTL_MS }
158+
{ ttl: organizationId ? MEMBERSHIP_CACHE_TTL_MS : NEGATIVE_MEMBERSHIP_CACHE_TTL_MS }
159159
)
160160
return organizationId
161161
}

apps/sim/lib/auth/session-policy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ async function isEntitledToEnforce(organizationId: string): Promise<boolean> {
6363
* than trying to keep two caches coherent.
6464
*
6565
* Throws if the read fails. Callers pick their own failure posture: the session
66-
* UPDATE hook refuses to extend, the CREATE hook allows the sign-in.
66+
* UPDATE hook keeps the current expiry rather than extending it, and the CREATE
67+
* hook refuses the sign-in when the governing org is known but allows it when
68+
* membership itself could not be resolved.
6769
*/
6870
export async function getSessionPolicy(
6971
organizationId: string | null | undefined

0 commit comments

Comments
 (0)