Skip to content

Commit

Permalink
fix(server): fix usage of rawBody
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 26, 2024
1 parent 7f795ab commit ac6d150
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion adapters/lark/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, FeishuBo
const result = enabledSignatureVerify.some((bot) => {
const timestamp = ctx.get('X-Lark-Request-Timestamp')
const nonce = ctx.get('X-Lark-Request-Nonce')
const body = ctx.request.rawBody
const body = ctx.request.body[Symbol.for('unparsedBody')]
const actualSignature = this.ciphers[bot.config.appId]?.calculateSignature(timestamp, nonce, body)
if (actualSignature === signature) return true
else return false
Expand Down
2 changes: 1 addition & 1 deletion adapters/line/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, LineBot<
const { destination } = parsed
const bot = this.bots.find(bot => bot.selfId === destination)
if (!bot) return ctx.status = 403
const hash = crypto.createHmac('SHA256', bot?.config?.secret).update(ctx.request.rawBody || '').digest('base64')
const hash = crypto.createHmac('SHA256', bot?.config?.secret).update(ctx.request.body[Symbol.for('unparsedBody')] || '').digest('base64')
if (hash !== sign) {
return ctx.status = 403
}
Expand Down
2 changes: 2 additions & 0 deletions adapters/qq/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ declare module '@satorijs/core' {
qq?: QQ.Payload & GroupInternal
qqguild?: QQ.Payload & GuildInternal
}
}

declare module 'cordis' {
interface Events extends QQEvents { }
}
2 changes: 1 addition & 1 deletion adapters/slack/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, SlackBot
this.ctx.server.post('/slack', async (ctx) => {
const timestamp = ctx.request.header['x-slack-request-timestamp'].toString()
const signature = ctx.request.header['x-slack-signature'].toString()
const requestBody = ctx.request.rawBody
const requestBody = ctx.request.body[Symbol.for('unparsedBody')]

const hmac = crypto.createHmac('sha256', signing)
const [version, hash] = signature.split('=')
Expand Down
4 changes: 2 additions & 2 deletions adapters/wechat-official/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WechatOf
const { timestamp, nonce, msg_signature } = ctx.request.query
let { xml: data }: {
xml: Message
} = await xml2js.parseStringPromise(ctx.request.rawBody, {
} = await xml2js.parseStringPromise(ctx.request.body[Symbol.for('unparsedBody')], {
explicitArray: false,
})
const botId = data.ToUserName
Expand All @@ -52,7 +52,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WechatOf
data = data2
}

bot.logger.debug('%c', ctx.request.rawBody)
bot.logger.debug('%c', ctx.request.body[Symbol.for('unparsedBody')])

const session = await decodeMessage(localBot, data)

Expand Down
4 changes: 2 additions & 2 deletions adapters/wecom/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WecomBot
const { timestamp, nonce, msg_signature } = ctx.request.query
let { xml: data }: {
xml: Message
} = await xml2js.parseStringPromise(ctx.request.rawBody, {
} = await xml2js.parseStringPromise(ctx.request.body[Symbol.for('unparsedBody')], {
explicitArray: false,
})
const botId = data.AgentID
Expand All @@ -52,7 +52,7 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WecomBot
data = data2
}

bot.logger.debug('%c', ctx.request.rawBody)
bot.logger.debug('%c', ctx.request.body[Symbol.for('unparsedBody')])

const session = await decodeMessage(localBot, data)
if (session) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/whatsapp/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HttpServer {
const received = ctx.get('X-Hub-Signature-256').split('sha256=')[1]
if (!received) return ctx.status = 403

const payload = ctx.request.rawBody
const payload = ctx.request.body[Symbol.for('unparsedBody')]
const adapters = this.adapters.filter((adapter) => {
const expected = crypto
.createHmac('sha256', adapter.config.secret)
Expand Down

0 comments on commit ac6d150

Please sign in to comment.