Skip to content

A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.

Shell

Require and consume Feishu callback state before token exchange

Rudy Celekliadf0b7268a90
diff --git a/engineering/engineering-feishu-integration-developer.md b/engineering/engineering-feishu-integration-developer.md
index 74d20868..a95f7d40 100644
--- a/engineering/engineering-feishu-integration-developer.md
+++ b/engineering/engineering-feishu-integration-developer.md
@@ -511,9 +511,17 @@ router.get('/login/feishu', (req, res) => {
router.get('/callback/feishu', async (req, res) => {
const { code, state } = req.query;
- if (state !== req.session!.oauthState) {
+ const expectedState = req.session?.oauthState;
+ if (typeof code !== 'string' || !code ||
+ typeof state !== 'string' || !state ||
+ typeof expectedState !== 'string' || !expectedState ||
+ state !== expectedState) {
return res.status(403).json({ error: 'State mismatch — possible CSRF attack' });
}
+ // Consume this request's session binding before the first await.
+ // If callbacks can load separate session copies, invalidate state atomically
+ // in the shared session store as well; deleting this object alone cannot do that.
+ delete req.session!.oauthState;
const tokenResp = await client.authen.oidcAccessToken.create({
data: {