किसी custom endpoint पर आने वाला हर अनुरोध आपके endpoint के secret से साइन किया जाता है। body पर भरोसा करने से पहले signature की जाँच करें।
इसे कैसे साइन किया जाता है
- signature, raw request body का HMAC-SHA256 होता है, जिसे आपके signing secret से key किया जाता है।
- इसे
X-Studio-Signature: sha256=<hex digest>के रूप में भेजा जाता है। - Secrets
whsec_से शुरू होते हैं। उन्हें endpoint page पर Signing secret के तहत देखें।
Node.js
import { createHmac, timingSafeEqual } from "node:crypto"
export function verify(rawBody: string, header: string, secret: string) {
const expected = `sha256=${createHmac("sha256", secret).update(rawBody).digest("hex")}`
const a = Buffer.from(header)
const b = Buffer.from(expected)
return a.length === b.length && timingSafeEqual(a, b)
}
Python
import hashlib, hmac
def verify(raw_body: bytes, header: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(header, expected)
सामान्य गलतियाँ
- आपको जो exact bytes मिले हैं, उन्हीं का hash करें। JSON को parse करके दोबारा serialize करने से bytes बदल जाते हैं, इसलिए signature match नहीं होगा।
- ऊपर दिए गए उदाहरणों की तरह
==के बजाय constant-time comparison का उपयोग करें। - Rotate secret के बाद, अपने server को तुरंत अपडेट करें। पुराना secret काम करना बंद कर देता है।
Slack जैसे chat-app destinations को इसके बजाय एक formatted message मिलता है, और वे signed नहीं होते।
क्या यह मददगार था?
कुछ ही मिनटों में ब्रांड के अनुरूप पोस्ट प्रकाशित करें
दस्तावेज़ पर वापस जाएँAI कंटेंट, शेड्यूलिंग, एंगेजमेंट और एक पूरी मार्केटिंग सूट — शुरू करने के लिए मुफ़्त।
मुफ़्त में शुरू करें









