@@ -4,11 +4,9 @@ import * as Lark from "@larksuiteoapi/node-sdk";
44import { createFeishuWSClient } from "./client.js" ;
55import {
66 applyBasicWebhookRequestGuards ,
7- isRequestBodyLimitError ,
87 type RuntimeEnv ,
98 installRequestBodyLimitGuard ,
10- readRequestBodyWithLimit ,
11- requestBodyErrorToText ,
9+ readWebhookBodyOrReject ,
1210 safeEqualSecret ,
1311} from "./monitor-transport-runtime-api.js" ;
1412import {
@@ -190,13 +188,20 @@ export async function monitorWebhook({
190188
191189 void ( async ( ) => {
192190 try {
193- const rawBody = await readRequestBodyWithLimit ( req , {
191+ const body = await readWebhookBodyOrReject ( {
192+ req,
193+ res,
194194 maxBytes : FEISHU_WEBHOOK_MAX_BODY_BYTES ,
195195 timeoutMs : FEISHU_WEBHOOK_BODY_TIMEOUT_MS ,
196+ profile : "pre-auth" ,
196197 } ) ;
197- if ( guard . isTripped ( ) || res . writableEnded ) {
198+ if ( ! body . ok || res . writableEnded ) {
198199 return ;
199200 }
201+ if ( guard . isTripped ( ) ) {
202+ return ;
203+ }
204+ const rawBody = body . value ;
200205
201206 // Reject invalid signatures before any JSON parsing to keep the auth boundary strict.
202207 if (
@@ -235,17 +240,9 @@ export async function monitorWebhook({
235240 res . end ( JSON . stringify ( value ) ) ;
236241 }
237242 } catch ( err ) {
238- if ( isRequestBodyLimitError ( err ) ) {
239- if ( ! res . headersSent ) {
240- respondText ( res , err . statusCode , requestBodyErrorToText ( err . code ) ) ;
241- }
242- return ;
243- }
244- if ( ! guard . isTripped ( ) ) {
245- error ( `feishu[${ accountId } ]: webhook handler error: ${ String ( err ) } ` ) ;
246- if ( ! res . headersSent ) {
247- respondText ( res , 500 , "Internal Server Error" ) ;
248- }
243+ error ( `feishu[${ accountId } ]: webhook handler error: ${ String ( err ) } ` ) ;
244+ if ( ! res . headersSent ) {
245+ respondText ( res , 500 , "Internal Server Error" ) ;
249246 }
250247 } finally {
251248 guard . dispose ( ) ;
0 commit comments