Analytics API Tokens Credentials हैं, Identifiers नहीं
API token डेटा तक पहुँच देता है। इसे lifecycle वाले secret की तरह संभालें: एक बार दिखाएँ, verifier स्टोर करें, अधिकार सीमित करें और revoke करना आसान रखें।
API token किसी user या site का label नहीं, बल्कि credential है। वैध token पाने वाला व्यक्ति उसके owner की तरह कार्रवाई कर सकता है। इसे identifier मानने पर यह logs, URLs, support screenshots और ऐसी लंबी अवधि की configuration में पहुँच जाता है जिसे कोई सुरक्षित रूप से revoke नहीं कर पाता।
IETF की जनवरी 2025 में प्रकाशित OAuth 2.0 Security Best Current Practice OAuth deployment के threat model और सुरक्षा सलाह को अपडेट करती है। व्यक्तिगत API token जरूरी नहीं कि OAuth access token हो, लेकिन मूल engineering principle वही है: possession-based credential को transit में सुरक्षित रखें, intended service तक सीमित करें और caller को जितना अधिकार चाहिए उतना ही दें।
Secret केवल एक बार दिखाएँ
Token को cryptographically secure random source और पर्याप्त entropy से बनाएँ, ताकि व्यावहारिक रूप से उसका अनुमान न लगाया जा सके। पूरा token सिर्फ निर्माण के समय लौटाएँ; बाद में पहचान के लिए non-secret prefix और खोज के लिए one-way verifier स्टोर करें। Database की कॉपी मिल जाने पर verifier, दोबारा इस्तेमाल किए जा सकने वाले plaintext credential से अधिक सुरक्षित है। सामान्य hash को password hash न समझें: API token में उच्च randomness होनी चाहिए, जबकि मानव passwords के लिए जानबूझकर धीमा password-hashing function चाहिए।
Product UI और API response में साफ बताएँ कि token केवल एक बार दिखेगा। उपयोगकर्ता creation screen से निकल जाए तो मूल secret वापस दिखाने के बजाय revoke और reissue का रास्ता दें। Token को query parameter, page URL, analytics event, error report या screenshot में कभी न रखें। Authorization header की तुलना में URL browser history, referrer, proxy logs और support tickets में अधिक आसानी से पहुँचते हैं।
Credential को सही जगह भेजें
HTTP API में TLS के ऊपर Authorization header से token स्वीकार करें। RFC 6750 bearer token को ऐसा credential बताता है जिसे उसका कोई भी धारक उपयोग कर सकता है, और चेतावनी देता है कि storage या transit में खुलासा दुरुपयोग की अनुमति देता है। यह URI query parameter में bearer credential रखने से भी बचने को कहता है, क्योंकि URL अक्सर log होते हैं। Query string और request body में आए token अस्वीकार करें, जब तक कोई protocol दूसरा transport अनिवार्य न करे और उसका threat model दस्तावेज़ित न हो।
Requested operation चलाने से पहले server पर token validate करें। Owner और permissions विश्वसनीय storage से निकालें; request में आए user या site owner को अधिकार का आधार न मानें। Secrets को application logs, traces और exception messages से बाहर रखें। Operational correlation जरूरी हो तो token का non-secret ID या prefix log करें, credential स्वयं नहीं।
Scope सीमित करें, expiry दें और revoke करें
Token को केवल आवश्यक न्यूनतम permissions देनी चाहिए। Product समर्थन करे तो user को token कुछ sites, read-only access या खास operations तक सीमित करने दें। केवल एक report लेने वाले automation script को पूरे account का write access चुपचाप न दें। OAuth security best practice token के privileges और audience सीमित करने पर चर्चा करती है; API अपना opaque format इस्तेमाल करे, तब भी यह उपयोगी design reference है।
Expiry और revocation को प्रमुख controls बनाएँ। छोटी lifetime से leaked credential के उपयोगी रहने की अवधि कम होती है; revocation incidents और team या integration में बदलाव संभालती है। Rotation में overlap चाहिए तो उसकी सीमा तय करें और दिखाएँ कि कौन-सा token सक्रिय है। Revocation API boundary पर लागू होनी चाहिए, केवल dashboard से token छिपाना काफी नहीं।
Monoid की programmatic API में user-created mnd_live_… tokens opaque होते हैं, plaintext में एक बार लौटाए जाते हैं और optional expiry व soft revocation के साथ SHA-256 hashes के रूप में स्टोर होते हैं। यह तरीका database पढ़े जाने पर मूल value बचाता है, लेकिन leaked active token को बेअसर नहीं करता। इसे source control, CI output, browser bundles और shared terminal history से बाहर रखें; exposure का संदेह हो तो नया token जारी करके पुराना revoke करें।
Lifecycle को test योग्य बनाएँ
पूरा flow test करें: create करना, अपेक्षित permissions से उपयोग, invalid या expired token अस्वीकार करना, revoke करना और पुष्टि करना कि वही token अब काम नहीं करता। जाँचें कि token दूसरे accounts या sites तक न पहुँचे और हर endpoint एक जैसे authentication और authorization rules लागू करे। Operational checks में यह भी सुनिश्चित करें कि logs credentials redact करें और API responses stored token material कभी न लौटाएँ।
Secret-management lifecycle में creation, access control, rotation, audit और revocation शामिल हैं—केवल सुरक्षित storage नहीं। API token तभी सुरक्षित रहता है जब system उसके owner को पहचान सके, अधिकार सीमित करे, secret रिकॉर्ड किए बिना exposure पकड़ सके और उसे जल्दी बंद कर सके।
Comments
Loading comments…