API Security: আধুনিক ওয়েব অ্যাপ্লিকেশনের API দিয়ে ডেটা লিক হচ্ছে না তো?
OWASP API Security Top 10 অনুযায়ী আধুনিক API-গুলোর সবচেয়ে বিপজ্জনক vulnerability এবং সেগুলো থেকে রক্ষার সম্পূর্ণ গাইড।
আধুনিক digital ecosystem-এ API হলো সেই অদৃশ্য সেতু যার উপর দিয়ে প্রতিদিন কোটি কোটি গিগাবাইট ডেটা প্রবাহিত হয়। আপনার mobile banking app যখন balance show করে, e-commerce site যখন product list দেখায়, বা social media app যখন notification পাঠায়—প্রতিটি কাজের পেছনে রয়েছে একাধিক API call। কিন্তু এই অপরিহার্য infrastructure-এর নিরাপত্তা প্রায়শই উপেক্ষিত। API Security এখন cybersecurity-এর সবচেয়ে দ্রুতগতিতে বিকশিত উপ-ক্ষেত্রগুলোর একটি, এবং প্রতিটি developer, security professional এবং architect-এর জন্য এর গভীর বোঝাপড়া অপরিহার্য। এই নিবন্ধে আমরা API Security-এর core concept, OWASP API Security Top 10, এবং বাস্তব আক্রমণের উদাহরণ বিশ্লেষণ করব।
API Security কেন আলাদা
Traditional web application security এবং API security-এর মধ্যে মৌলিক পার্থক্য রয়েছে। Web application সাধারণত human user-এর সঙ্গে interact করে, যেখানে session, cookie, এবং CSRF protection-এর প্রাসঙ্গিকতা থাকে। API অন্যদিকে machine-to-machine communication-এ ব্যবহৃত হয়, প্রায়শই stateless, এবং token-based authentication-এর উপর নির্ভরশীল।
API-এর আরেকটি বৈশিষ্ট্য হলো তারা backend logic এবং data structure সরাসরি expose করে। একটি REST API যখন /api/users/123 endpoint provide করে, এটি সরাসরি একটি database object-এর reference। যদি proper authorization না থাকে, attacker সহজেই /api/users/124, /api/users/125 চেষ্টা করে অন্যের ডেটা access করতে পারে। এই ধরনের vulnerability—Broken Object Level Authorization (BOLA)—API-এর সবচেয়ে কমন এবং বিপজ্জনক সমস্যা।
আরেকটি দিক হলো API documentation এবং discoverability। Swagger/OpenAPI specification, GraphQL introspection, এবং mobile app reverse engineering-এর মাধ্যমে attacker সহজেই API-এর সম্পূর্ণ structure বুঝতে পারে। ফলে obscurity-based security কাজ করে না।
OWASP API Security Top 10
OWASP API Security Top 10 হলো API-specific vulnerabilities-এর authoritative list। ২০২৩ সালে আপডেটেড version-এ নিম্নলিখিত categories রয়েছে।
API1:2023 - Broken Object Level Authorization (BOLA): আগেই উল্লেখ করা সবচেয়ে কমন vulnerability। User A তার নিজস্ব resource access করার পরিবর্তে User B-এর resource ID দিয়ে request করে এবং backend authorization check না করে data ফেরত দেয়।
API2:2023 - Broken Authentication: Weak password policy, unencrypted credential transmission, predictable token, এবং improper session management। JWT-এর none algorithm accept করা, weak signing key ব্যবহার করা, এবং token expiration check না করা সাধারণ ভুল।
API3:2023 - Broken Object Property Level Authorization: এটি Excessive Data Exposure এবং Mass Assignment-এর সংমিশ্রণ। API সম্পূর্ণ object return করে, যেখানে শুধু কয়েকটি field প্রয়োজন। বা client-side থেকে আসা সব field directly database-এ assign হয়, যার ফলে attacker isAdmin: true যোগ করে privilege escalate করতে পারেন।
API4:2023 - Unrestricted Resource Consumption: Rate limiting, payload size limit, query complexity limit-এর অভাব। GraphQL-এ nested query দিয়ে DoS attack, file upload-এ massive file দিয়ে storage exhaust করা।
API5:2023 - Broken Function Level Authorization: Admin endpoint যেমন /admin/users/delete regular user থেকে accessible থাকা। প্রায়ই UI-তে button hide করা হয় কিন্তু backend-এ authorization check নেই।
API6:2023 - Unrestricted Access to Sensitive Business Flows: Critical business flow যেমন ticket purchase, account creation-এ proper anti-automation control না থাকা। Bot দিয়ে massive ticket buying, fake account creation।
API7:2023 - Server Side Request Forgery (SSRF): API user-supplied URL fetch করার সময় internal network resource access করার সুযোগ দিচ্ছে। Cloud metadata endpoint (169.254.169.254) access করে credential চুরি করা সম্ভব।
API8:2023 - Security Misconfiguration: Default credential, verbose error message, missing security headers, unnecessary HTTP method allowed (PUT, DELETE)।
API9:2023 - Improper Inventory Management: Shadow API, deprecated API version যা এখনও চলছে, undocumented endpoint। প্রতিষ্ঠান জানে না তাদের কতগুলো API আছে।
API10:2023 - Unsafe Consumption of APIs: Third-party API-এর response blindly trust করা। এটি reverse direction-এর সমস্যা—আপনার API অন্য API-কে call করছে এবং সেই response সুরক্ষিতভাবে handle করছে না।
Authentication Patterns
API authentication-এর জন্য বিভিন্ন pattern প্রচলিত। সবচেয়ে সরল হলো API key, যা একটি static string client প্রতিটি request-এ পাঠায়। এটি simple কিন্তু rotation কঠিন এবং leak হলে full access compromise।
OAuth 2.0 আধুনিক standard, যেখানে authorization server থেকে token issued হয়। Different grant type—Authorization Code, Client Credentials, Resource Owner Password (deprecated)—different use case-এর জন্য designed। OpenID Connect (OIDC) OAuth-এর উপর built একটি identity layer যা authentication add করে।
JWT (JSON Web Token) self-contained token যা claim-based authorization enable করে। তবে JWT-এর কিছু সাধারণ pitfall আছে—alg: none accept করা, secret key brute-force-এ vulnerable হওয়া, এবং revocation কঠিন হওয়া। Production-এ short-lived access token এবং refresh token pattern follow করা উচিত।
মobile এবং SPA-এর জন্য PKCE (Proof Key for Code Exchange) extension OAuth-এ যোগ করা হয়েছে authorization code interception attack রোধে। মobile app-এ Implicit Flow এখন discouraged।
GraphQL এবং gRPC Security
GraphQL-এ unique security challenge রয়েছে। Query complexity attack-এ deeply nested query দিয়ে server overload করা সম্ভব। উদাহরণস্বরূপ, একটি social network API-তে friends-of-friends-of-friends query exponentially expand হতে পারে। Query depth limit, complexity scoring, এবং rate limiting এই সমস্যার সমাধান।
GraphQL introspection by default enabled থাকে, যা attacker-কে complete schema reveal করে। Production-এ introspection disable বা restricted করতে হবে। তবে শুধু introspection disable করা সব সমস্যার সমাধান নয়—schema fingerprinting-এর মাধ্যমে এখনও infer করা সম্ভব।
gRPC binary protocol (Protocol Buffers) ব্যবহার করে, যা traditional HTTP-based testing tool-এর জন্য চ্যালেঞ্জ। gRPC-Web এবং reflection enabled থাকলে attacker সহজে service definition পেতে পারে। mTLS, proper authentication interceptor, এবং reflection disable করা gRPC security-এর core practice।
Data Validation এবং Output Encoding
প্রতিটি API input-কে untrusted হিসেবে treat করতে হবে। JSON Schema-based validation নিশ্চিত করে যে শুধু expected structure accept হবে। তবে structural validation যথেষ্ট নয়—semantic validation প্রয়োজন। একটি email field-এ valid format থাকতে পারে কিন্তু business rule অনুযায়ী এটি unique হতে হবে।
Output-এ data exposure সমান গুরুত্বপূর্ণ। Backend object সরাসরি serialize করে return করা একটি কমন ভুল। Response DTO (Data Transfer Object) ব্যবহার করে শুধু necessary field expose করা উচিত। User object-এ password hash, security question answer, internal admin flag—কিছুই API response-এ আসা উচিত নয়, এমনকি সরিয়ে নেওয়ার পরও।
Error message-এ sensitive information leak হতে পারে। User [email protected] not found versus Invalid credentials দ্বিতীয়টা user enumeration prevent করে। Stack trace, SQL query, internal file path production response-এ কখনো আসা উচিত নয়।
API Security Testing
API security testing-এর জন্য বিভিন্ন approach রয়েছে। Static Application Security Testing (SAST) tool যেমন Semgrep, Checkmarx source code analyze করে। তবে API-specific bug অনেক সময় code structure-এ ধরা পড়ে না।
Dynamic Application Security Testing (DAST) live API-তে test করে। OWASP ZAP, Burp Suite Professional, এবং specialized API security platform যেমন Salt Security, 42Crunch, এবং Akto এই কাজ করে। এরা OpenAPI specification-এর সঙ্গে compare করে missing endpoint, drift, এবং vulnerability শনাক্ত করে।
Fuzzing API security testing-এর একটি শক্তিশালী technique। RESTler (Microsoft Research), Schemathesis, এবং custom fuzzer schema-aware mutation দিয়ে edge case test করে। Boundary value, special character, unexpected type—এসব fuzz করে runtime error এবং security issue ধরা পড়ে।
Manual penetration testing-এর মাধ্যমে business logic flaw, complex authorization bug, এবং chain attack identify করা যায়। Automated tool এসব ধরতে পারে না কারণ এগুলো business context-dependent।
বাস্তব ঘটনার উদাহরণ
Facebook-এর ২০১৮ সালের "View As" feature-এর breach API security-এর একটি landmark case। একটি OAuth-related bug-এর কারণে attacker ৫০ মিলিয়ন user-এর access token চুরি করতে পেরেছিল। এই incident demonstrate করেছে যে API access token কতটা powerful এবং তাদের সুরক্ষা কতটা critical।
USPS (United States Postal Service)-এর ২০১৮ সালের incident-এ একটি authenticated API endpoint যেকোনো user-কে অন্য user-এর account data access করতে দিচ্ছিল—classic BOLA। ৬০ মিলিয়ন account exposed ছিল।
Coinbase-এর ২০২২ সালের incident-এ একটি retail advanced trading API-এর validation bug-এর কারণে user-রা trade conditions বদলিয়ে অন্যের ক্ষতিতে লাভ করতে পারছিলেন। যদিও Coinbase দ্রুত patch করে এবং bug bounty দেয়, এটি business logic flaw-এর severe implication দেখায়।
Twitter (এখন X)-এর ২০২২ সালের API incident-এ একটি unauthenticated endpoint phone number বা email-এর মাধ্যমে user enumeration করতে দিচ্ছিল। ৫.৪ মিলিয়ন account-এর data dark web-এ বিক্রি হয়েছিল।
API Security আধুনিক সফটওয়্যার ecosystem-এর সবচেয়ে critical এবং দ্রুত বিকশিত নিরাপত্তা ক্ষেত্রগুলোর একটি। OWASP API Security Top 10-এর প্রতিটি category বুঝে এবং সেই অনুযায়ী defensive measure প্রয়োগ করে আমরা আমাদের systems-কে অনেকাংশে সুরক্ষিত করতে পারি। তবে শুধু checklist মেনে চলা যথেষ্ট নয়—security mindset-কে development culture-এর অবিচ্ছেদ্য অংশ করতে হবে। Shift-left security, automated testing in CI/CD, এবং continuous monitoring-এর সমন্বয়ে গঠিত holistic approach API-কে evolving threat landscape থেকে রক্ষা করতে পারে। যারা application security বা cloud security-তে career গড়তে চান, তাদের জন্য API security expertise অপরিহার্য দক্ষতা।
আপনার জ্ঞান যাচাই করতে প্রস্তুত? আজই HackCert-এ API Security MCQ Quiz-টি দিন!
Related articles
Mass Assignment: Exploiting Web API Vulnerabilities for Privilege Escalation
10 min
API Hardening: A Comprehensive Guide to Ensuring API Security and Avoiding Cyber Risks
8 min
Blind SQLi: Advanced Techniques to Extract Sensitive Data from Databases
12 min
Cache Poisoning: Manipulating Web Servers to Serve Malicious Payloads
8 min

