Skip to content

Commit 82c66a1

Browse files
committed
Fix types & lint
1 parent 587fc0d commit 82c66a1

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

apps/backend/src/lib/oauth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createOrUpgradeAnonymousUserWithRules, SignUpRuleOptions } from "@/lib/
44
import { PrismaClientTransaction } from "@/prisma-client";
55
import { UsersCrud } from "@stackframe/stack-shared/dist/interface/crud/users";
66
import { KnownErrors } from "@stackframe/stack-shared/dist/known-errors";
7-
import { StackAssertionError, captureError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
7+
import { captureError, StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
88

99
/**
1010
* Find an existing OAuth account for sign-in.

apps/backend/src/lib/sign-up-rules.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ export type SignUpRuleAction = {
2525
/**
2626
* A sign-up rule from the config.
2727
* Type definition for the signUpRules field in auth config.
28+
* Note: All fields except metadata are required after config defaults are applied.
2829
*/
2930
type SignUpRuleConfig = {
30-
enabled?: boolean,
31-
displayName?: string,
32-
priority?: number,
33-
condition?: string,
34-
action?: {
35-
type?: 'allow' | 'reject' | 'restrict' | 'log' | 'add_metadata',
36-
message?: string,
37-
metadata?: Record<string, SignUpRuleMetadataEntry>,
31+
enabled: boolean,
32+
displayName: string | undefined,
33+
priority: number,
34+
condition: string | undefined,
35+
action: {
36+
type: 'allow' | 'reject' | 'restrict' | 'log' | 'add_metadata',
37+
message: string | undefined,
38+
metadata: Record<string, SignUpRuleMetadataEntry> | undefined,
3839
},
3940
};
4041

@@ -123,21 +124,21 @@ export async function evaluateSignUpRules(
123124
const sortedRuleEntries = Object.entries(rules)
124125
.filter(([, rule]) => rule.enabled)
125126
.sort((a, b) => {
126-
const priorityA = a[1].priority ?? 0;
127-
const priorityB = b[1].priority ?? 0;
127+
const priorityA = a[1].priority;
128+
const priorityB = b[1].priority;
128129
if (priorityA !== priorityB) return priorityA - priorityB;
129130
return stringCompare(a[0], b[0]);
130131
});
131132

132133
// Evaluate each rule in order
133134
for (const [ruleId, rule] of sortedRuleEntries) {
134-
if (!rule.condition || !rule.action) continue;
135+
if (!rule.condition) continue;
135136

136137
try {
137138
const matches = evaluateCelExpression(rule.condition, context);
138139
if (matches) {
139140
const action: SignUpRuleAction = {
140-
type: rule.action.type ?? 'allow',
141+
type: rule.action.type,
141142
metadata: rule.action.metadata,
142143
message: rule.action.message,
143144
};
@@ -178,7 +179,8 @@ export function applySignUpRuleAction(result: SignUpRuleResult): {
178179
switch (result.action.type) {
179180
case 'reject': {
180181
// Throw an error to reject the signup
181-
// Don't include the custom rule message to avoid helping users evade rules
182+
// Note: We intentionally don't pass the custom message to avoid helping users evade rules
183+
// The custom message is only for internal logging/analytics purposes
182184
throw new KnownErrors.SignUpRejected();
183185
}
184186
case 'restrict': {

apps/backend/src/lib/users.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { usersCrudHandlers } from "@/app/api/latest/users/crud";
22
import { UsersCrud } from "@stackframe/stack-shared/dist/interface/crud/users";
33
import { KeyIntersect } from "@stackframe/stack-shared/dist/utils/types";
4-
import { Tenancy } from "./tenancies";
54
import { createSignUpRuleContext } from "./cel-evaluator";
6-
import { evaluateAndApplySignUpRules, SignUpRuleMetadataEntry } from "./sign-up-rules";
5+
import { evaluateAndApplySignUpRules } from "./sign-up-rules";
6+
import { Tenancy } from "./tenancies";
77

88
/**
99
* Options for sign-up rule evaluation context.

apps/e2e/tests/backend/endpoints/api/v1/auth/sign-up-rules.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe("sign-up rules", () => {
8484
});
8585
});
8686

87-
it("should use custom rejection message from rule", async ({ expect }) => {
87+
it("should reject sign-up when rule with custom message matches (message is for internal use only)", async ({ expect }) => {
8888
await Project.createAndSwitch({
8989
config: {
9090
credential_enabled: true,
@@ -101,6 +101,7 @@ describe("sign-up rules", () => {
101101
condition: 'emailDomain == "blocked-domain.com"',
102102
action: {
103103
type: 'reject',
104+
// Note: This message is for internal logging/analytics only, not shown to users
104105
message: customMessage,
105106
},
106107
},
@@ -119,8 +120,9 @@ describe("sign-up rules", () => {
119120
expect(response.status).toBe(403);
120121
expect(response.body).toMatchObject({
121122
code: 'SIGN_UP_REJECTED',
122-
error: customMessage,
123123
});
124+
// Custom message is intentionally NOT exposed to users to avoid helping evade rules
125+
expect(response.body.error).not.toContain(customMessage);
124126
});
125127

126128
// ==========================================

0 commit comments

Comments
 (0)