Skip to content

Commit 5968f3b

Browse files
waleedlatif1claude
andcommitted
fix(cors): allow PUT in embed CORS policy for OTP verification
Both /api/chat/[identifier]/otp and /api/form/[identifier]/otp export PUT for OTP code verification. The embed policy advertised only GET/POST/OPTIONS, so cross-origin embed clients failed preflight on verify. Add PUT and assert it in the embed policy test. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 80aa102 commit 5968f3b

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

apps/sim/proxy.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,19 @@ describe('resolveApiCorsPolicy', () => {
5757
expect(policy).toEqual({
5858
origin: 'https://customer.example',
5959
credentials: false,
60-
methods: 'GET, POST, OPTIONS',
60+
methods: 'GET, POST, PUT, OPTIONS',
6161
headers: 'Content-Type, X-Requested-With',
6262
})
6363
}
6464
})
6565

66+
it('allows PUT on the embed policy (used by OTP verification on /[identifier]/otp)', () => {
67+
const policy = resolveApiCorsPolicy(
68+
makeRequest('/api/chat/abc/otp', 'https://customer.example')
69+
)
70+
expect(policy.methods).toContain('PUT')
71+
})
72+
6673
it('falls back to wildcard for chat/form embeds when no origin header is present', () => {
6774
expect(resolveApiCorsPolicy(makeRequest('/api/chat/abc')).origin).toBe('*')
6875
})

apps/sim/proxy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ const CORS_RULES: readonly CorsRule[] = [
8989
policy: (request) => ({
9090
origin: request.headers.get('origin') || '*',
9191
credentials: false,
92-
methods: 'GET, POST, OPTIONS',
92+
// PUT is required for OTP verification on /[identifier]/otp.
93+
methods: 'GET, POST, PUT, OPTIONS',
9394
headers: 'Content-Type, X-Requested-With',
9495
}),
9596
},

0 commit comments

Comments
 (0)