<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Curious engineer's playground]]></title><description><![CDATA[Curious engineer's playground]]></description><link>https://www.curious-engineer.com</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 21:24:09 GMT</lastBuildDate><atom:link href="https://www.curious-engineer.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[secure your APIs]]></title><description><![CDATA[What are APIs and why are they important?
An Application Programming Interface (API) is a well-defined set of protocols and tools that enables communication between software applications. It acts as an intermediary, allowing programs to request and r...]]></description><link>https://www.curious-engineer.com/secure-your-apis</link><guid isPermaLink="true">https://www.curious-engineer.com/secure-your-apis</guid><category><![CDATA[#apisecurity]]></category><category><![CDATA[APIs]]></category><dc:creator><![CDATA[Vivek]]></dc:creator><pubDate>Tue, 14 Jan 2025 23:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1737653307116/592c69e6-0e3b-4c22-a2f5-16ade164ee6c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-are-apis-and-why-are-they-important">What are APIs and why are they important?</h3>
<p>An Application Programming Interface (API) is a well-defined set of protocols and tools that enables communication between software applications. It acts as an intermediary, allowing programs to request and receive data from each other in a structured and secure way. One system do not need to know the internals of other system in order to communicate instead they just to agree on certain rules like protocols and structure.</p>
<p>Imagine if every app you used tried to be all things to all people. Your music app would try to navigate you places, your photo editing app would also send messages, and your social media app would… well, it already tries to do everything! But the truth is, it’s hard for one company to be the best at everything. That’s where APIs come in. APIs act like translators between different programs, allowing them to share features and data. This lets your favorite apps focus on what they do best – like editing photos or keeping you connected – and borrow functionalities from others to offer a wider range of features. So next time you seamlessly switch between editing a picture and sharing it on social media, thank the magic of APIs for making it all work smoothly behind the scenes.</p>
<p>I remember, in the early days of APIs, developing and using them was a complex chore. Even with technologies like <a target="_blank" href="https://en.wikipedia.org/wiki/Distributed_Component_Object_Model">DCOM</a>, <a target="_blank" href="https://en.wikipedia.org/wiki/Common_Object_Request_Broker_Architecture">CORBA</a> or <a target="_blank" href="https://en.wikipedia.org/wiki/SOAP">SOAP</a> trying to smooth things over, frequent updates to different systems created constant compatibility headaches. Imagine building with Legos where the pieces changed size and shape every few weeks - that was the challenge of early APIs! Thankfully, things have become much more standardized and user-friendly today.</p>
<p>REST-based APIs using JSON are the most common today, and nearly all popular programming languages have several frameworks that allow you to develop REST APIs.</p>
<p>Since APIs often handle sensitive information and critical features, their security is crucial in system design. Unsecured APIs can break trust and even violate laws. Strong API security protects sensitive information and ensures everything operates smoothly.</p>
<p>There are mainly four ways through which we secure our APIs:</p>
<ol>
<li><p><strong>Robust Authentication and Authorization</strong></p>
</li>
<li><p><strong>Encryption in Transit and at Rest</strong></p>
</li>
<li><p><strong>Input Validation and Sanitization</strong></p>
</li>
<li><p><strong>Rate Limiting and Threat Monitoring</strong></p>
</li>
</ol>
<p>For this article I would only talk about point #1 <strong>Authentication</strong> and <strong>Authorization</strong>.</p>
<h3 id="heading-quick-refresher-on-authentication-vs-authorization">quick refresher on Authentication vs Authorization</h3>
<p>The difference between authentication and authorization is the same as who and what. Authentication deals with who should get into the system and Authorization handles what data should be accessible.</p>
<h2 id="heading-what-is-oauth-20">What is OAuth 2.0?</h2>
<p>OAuth is a short for Open Authorization. It is an industry-standard framework for secure authorization delegation. It streamlines user login and data access between applications from trusted providers (like Facebook or Google) without ever directly acquiring passwords.</p>
<p>Here's a breakdown:</p>
<ol>
<li><p><strong>Authorization Request:</strong> The application requests permission to access specific user resources on a trusted provider's platform (e.g., Facebook profile information).</p>
</li>
<li><p><strong>User Consent:</strong> The user explicitly grants or denies this permission on the trusted provider's platform.</p>
</li>
<li><p><strong>Secure Access Token:</strong> If granted, the trusted provider issues a secure access token to the application. This token grants controlled access to the authorized resources, but doesn't contain the user's password.</p>
</li>
<li><p><strong>API Access:</strong> The application uses the access token to access the authorized user resources on the trusted provider's API.</p>
</li>
</ol>
<p>OAuth 2.0 offers several benefits:</p>
<ul>
<li><p><strong>Enhanced Security:</strong> Eliminates the need for applications to store user passwords, reducing the risk of data breaches.</p>
</li>
<li><p><strong>Convenience:</strong> Users can avoid creating and managing additional login credentials for various applications.</p>
</li>
<li><p><strong>Improved User Experience:</strong> Streamlined login process fosters better user engagement.</p>
</li>
</ul>
<p>read more <a target="_blank" href="https://auth0.com/intro-to-iam/what-is-oauth-2#">here</a>.</p>
<h2 id="heading-auth0">Auth0</h2>
<p>Auth0 is a paid platform which makes authentication and authorization extremely easy. Feel free to signup for <a target="_blank" href="http://auth0.com/">Auth0</a>. I have used the free version and its enough to understand the whole process.</p>
<h2 id="heading-encryption-in-transit-and-at-rest">Encryption in Transit and at Rest</h2>
<p>Now let's talk about the second way to secure our APIs - encryption. Think of encryption like sending your data in a locked briefcase rather than an open envelope. Even if someone intercepts it, they can't read what's inside without the key.</p>
<p><strong>Encryption in Transit</strong> means protecting data while it's traveling between the client and server. All API communications should use HTTPS/TLS to encrypt this data. This prevents man-in-the-middle attacks where bad actors try to intercept and read your sensitive information.</p>
<p>Here are the key practices:</p>
<ol>
<li><p><strong>Always use HTTPS:</strong> Never use plain HTTP for API endpoints - it's like shouting your secrets in a crowded room.</p>
</li>
<li><p><strong>Use TLS 1.2 or higher:</strong> TLS 1.3 is even better and offers improved security and performance.</p>
</li>
<li><p><strong>Strong cipher suites:</strong> Disable weak encryption methods that attackers can easily crack.</p>
</li>
<li><p><strong>Certificate pinning:</strong> For mobile apps, this prevents attackers from using fake certificates.</p>
</li>
</ol>
<p><strong>Encryption at Rest</strong> protects data when it's stored in your databases or file systems. Even if someone gains access to your storage, they can't read encrypted data without the decryption keys.</p>
<p>Best practices include:</p>
<ul>
<li><p><strong>AES-256 encryption:</strong> Use strong encryption for sensitive database fields.</p>
</li>
<li><p><strong>Separate key storage:</strong> Keep encryption keys in dedicated services like AWS KMS, Azure Key Vault, or HashiCorp Vault - never store them alongside your data.</p>
</li>
<li><p><strong>Field-level encryption:</strong> Extra protection for highly sensitive data like passwords and credit card numbers.</p>
</li>
<li><p><strong>Key rotation:</strong> Regularly change your encryption keys to limit exposure if one gets compromised.</p>
</li>
</ul>
<h2 id="heading-input-validation-and-sanitization">Input Validation and Sanitization</h2>
<p>The third security measure is all about not trusting user input - ever. Attackers love to send malicious data through API requests hoping to break your system or steal information.</p>
<p>Common attacks include SQL injection, cross-site scripting (XSS), and command injection. Proper validation and sanitization acts as your first line of defense against these threats.</p>
<p><strong>Validation</strong> means checking if the input matches what you expect:</p>
<ol>
<li><p><strong>Whitelist approach:</strong> Define exactly what valid input looks like rather than trying to block every possible bad input.</p>
</li>
<li><p><strong>Type checking:</strong> If you expect a number, reject anything that isn't a number.</p>
</li>
<li><p><strong>Length limits:</strong> Set maximum lengths to prevent buffer overflow attacks.</p>
</li>
<li><p><strong>Format validation:</strong> Use patterns to validate emails, phone numbers, and dates.</p>
</li>
<li><p><strong>Range checks:</strong> Ensure numbers fall within acceptable limits.</p>
</li>
</ol>
<p><strong>Sanitization</strong> means cleaning the input before using it:</p>
<ul>
<li><p><strong>Escape special characters:</strong> Prevent them from being interpreted as code.</p>
</li>
<li><p><strong>Parameterized queries:</strong> The best defense against SQL injection - never concatenate user input into SQL statements.</p>
</li>
<li><p><strong>Content Security Policy:</strong> HTTP headers that help prevent XSS attacks.</p>
</li>
<li><p><strong>Strip HTML tags:</strong> Unless you explicitly need them, remove HTML from user input.</p>
</li>
</ul>
<p>Consider using JSON Schema to define and enforce the structure of your API requests. This ensures only properly formatted data gets processed.</p>
<h2 id="heading-rate-limiting-and-threat-monitoring">Rate Limiting and Threat Monitoring</h2>
<p>The fourth pillar focuses on controlling who can use your API and how much. Without rate limiting, attackers can overwhelm your servers or attempt brute force attacks.</p>
<p><strong>Rate limiting</strong> restricts how many requests a client can make within a given time period. This protects against:</p>
<ul>
<li><p><strong>DoS attacks:</strong> Overwhelming your API with requests to make it unavailable.</p>
</li>
<li><p><strong>Brute force attacks:</strong> Repeated attempts to guess passwords or tokens.</p>
</li>
<li><p><strong>Data scraping:</strong> Unauthorized mass extraction of your data.</p>
</li>
<li><p><strong>Cost control:</strong> Preventing abuse that could spike your infrastructure costs.</p>
</li>
</ul>
<p>Common strategies include:</p>
<ol>
<li><p><strong>Fixed window:</strong> Allow X requests per minute (e.g., 100 requests per minute).</p>
</li>
<li><p><strong>Sliding window:</strong> More sophisticated tracking that handles burst traffic better.</p>
</li>
<li><p><strong>Token bucket:</strong> Allows occasional bursts while maintaining an average rate.</p>
</li>
<li><p><strong>Per-endpoint limits:</strong> Stricter limits for expensive or sensitive operations.</p>
</li>
</ol>
<p><strong>Threat Monitoring</strong> helps you detect and respond to security issues in real-time:</p>
<ul>
<li><p><strong>Comprehensive logging:</strong> Track timestamps, IP addresses, user IDs, endpoints accessed, and response codes.</p>
</li>
<li><p><strong>Anomaly detection:</strong> Watch for unusual patterns like spikes in failed logins or requests from unusual locations.</p>
</li>
<li><p><strong>Alerting:</strong> Get notified about suspicious activities like repeated 401/403 errors or potential injection attempts.</p>
</li>
<li><p><strong>Regular audits:</strong> Periodically review logs and conduct penetration testing.</p>
</li>
</ul>
<p>Tools like Datadog, New Relic, Prometheus with Grafana, or cloud-native solutions like AWS CloudWatch can help you implement effective monitoring.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>API security isn't a one-time setup - it's an ongoing process. Threats evolve, new vulnerabilities emerge, and your API grows and changes over time.</p>
<p>Remember the four pillars we discussed:</p>
<ol>
<li><p><strong>Robust Authentication and Authorization</strong> - Ensure only the right users access the right resources.</p>
</li>
<li><p><strong>Encryption in Transit and at Rest</strong> - Protect data whether it's moving or stored.</p>
</li>
<li><p><strong>Input Validation and Sanitization</strong> - Never trust user input.</p>
</li>
<li><p><strong>Rate Limiting and Threat Monitoring</strong> - Control access and watch for suspicious activity.</p>
</li>
</ol>
<p>By implementing all four, you create defense in depth - multiple layers of security that protect your API, your users, and your business. A single weakness can compromise everything, so take security seriously from day one.</p>
<p>For those getting started, platforms like Auth0, AWS API Gateway, Kong, or Apigee offer built-in security features. But understanding these principles helps you make better decisions and customize security for your specific needs.</p>
]]></content:encoded></item><item><title><![CDATA[pro tips - for integration with external service provider APIs]]></title><description><![CDATA[Integrating your product with an external API is a critical step in expanding your application’s functionality and improving its user experience. However, it comes with its challenges and requires careful planning. Below, I outline 10 pro tips that w...]]></description><link>https://www.curious-engineer.com/pro-tips-for-integration-with-external-service-provider-apis</link><guid isPermaLink="true">https://www.curious-engineer.com/pro-tips-for-integration-with-external-service-provider-apis</guid><category><![CDATA[APIs]]></category><category><![CDATA[OAuth 2.0]]></category><dc:creator><![CDATA[Vivek]]></dc:creator><pubDate>Sat, 21 Dec 2024 23:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Integrating your product with an external API is a critical step in expanding your application’s functionality and improving its user experience. However, it comes with its challenges and requires careful planning. Below, I outline <strong>10 pro tips</strong> that will guide you to success when working with external service providers.</p>
<ol>
<li><p>Endpoint location for all environments  </p>
<p> Before integrating, ensure you know the API endpoint locations for all environments—development, staging, testing, and production. Misusing production endpoints during development could cause unintended effects, such as accidental transactions or data alterations.</p>
<p> <strong>Tip</strong>: Always configure environment-specific endpoints in a centralized configuration file to avoid hardcoding.</p>
</li>
<li><p>Check for existing firewalls on both sides</p>
</li>
</ol>
<p>    Network connectivity issues are common when firewalls block access to external APIs. Work with your network team and the API provider to confirm that: - The API’s IP addresses or domains are whitelisted on your end. - Your IP or network range is whitelisted on their end if required.</p>
<p>    <strong>Tip</strong>: Use diagnostic tools like <strong>ping</strong> or <strong>curl</strong> to test connectivity before proceeding with deeper integration.</p>
<ol start="3">
<li><p>Find out what type of authentication is implemented</p>
<p> Understanding the authentication method is crucial for securely accessing the API. Common methods include:</p>
<p> • <strong>API Keys</strong>: Simple but should be stored securely.</p>
<p> • <strong>OAuth 2.0 / OIDC</strong>: Often used for user-based permissions.</p>
<p> • <strong>JWT Tokens</strong>: Compact and secure, suitable for stateless authentication.</p>
<p> <strong>Tip</strong>: Use environment variables or secrets management tools to store and retrieve authentication credentials securely.</p>
</li>
<li><p>Find out if it’s secured ?</p>
<p> APIs must be secured to prevent data leaks or malicious activities. Ensure that:</p>
<p> • The API uses HTTPS for encrypted communication.</p>
<p> • Request headers or payloads don’t expose sensitive information.</p>
<p> • Certificates are valid and regularly updated.</p>
<p> <strong>Tip</strong>: Consider tools like OWASP ZAP to check for vulnerabilities in API integration.</p>
</li>
<li><p>If there is any data protection involved like GDPR or HIPAA etc ? Is there any legal compliance like Terms &amp; Conditions or Licensing</p>
<p> If the API deals with sensitive information, ensure it complies with regulations like <strong>GDPR</strong>, <strong>HIPAA</strong>, or <strong>CCPA</strong>. Additionally, review legal terms, including:</p>
<p> • <strong>Terms and Conditions</strong>: Defines acceptable use of the API.</p>
<p> • <strong>Licensing</strong>: Specifies restrictions or fees for data usage.</p>
<p> <strong>Tip</strong>: Have your legal team review compliance terms and consult them about liability in case of data breaches.</p>
</li>
<li><p>If there is any rate limit for API consumption?</p>
<p> Most APIs enforce rate limits to ensure fair usage and prevent abuse. Exceeding these limits can result in:</p>
<p> • Temporary or permanent bans.</p>
<p> • Additional costs for overages.</p>
<p> <strong>Tip</strong>: Implement rate-limiting mechanisms in your application to respect API limits, and consider caching frequent responses to reduce calls.</p>
</li>
<li><p>Ask for Technical documentation having information about API, versions, error codes and its description</p>
<p> Good documentation is the backbone of any successful API integration. Request the following details:</p>
<p> • API versions and their deprecation timelines.</p>
<p> • Error codes and detailed descriptions for debugging.</p>
<p> • Example payloads for requests and responses.</p>
<p> <strong>Tip</strong>: Keep the documentation accessible for your team and ensure developers are familiar with it before coding.</p>
</li>
<li><p>Ask about scalability concerns based on your estimate</p>
<p> If you expect heavy usage, discuss scalability concerns with the provider. Key questions include:</p>
<p> • Can the API handle the volume of requests you anticipate?</p>
<p> • Are there plans for improving scalability in the future?</p>
<p> <strong>Tip</strong>: Perform load testing during development to identify potential bottlenecks and plan accordingly.</p>
</li>
<li><p>Ask for advance schedule of maintenance and release</p>
<p> API providers often perform maintenance or release updates that might cause service interruptions. To prepare:</p>
<p> • Request advance notifications for planned downtimes.</p>
<p> • Inquire about backward compatibility for updates.</p>
<p> <strong>Tip</strong>: Implement a fallback mechanism for critical operations during downtime, such as retrying after a set interval or using cached data.</p>
</li>
<li><p>Have your own monitoring dashboard built where you record all failures including the failures of external APIs. Also, setup notification for critical API failure like payment.</p>
<p>A custom monitoring solution ensures visibility into your integration’s performance. Key features to include:</p>
<p>• Logs of API requests, responses, and failures.</p>
<p>• Notifications for critical API failures (e.g., payment, user authentication).</p>
<p><strong>Tip</strong>: Use tools like <strong>Prometheus</strong> or <strong>ELK Stack</strong> to aggregate and analyze logs, and configure alerts using <strong>Slack</strong>, <strong>PagerDuty</strong>, or email.</p>
</li>
</ol>
<p>By following these tips, you’ll minimize risks, ensure a seamless integration, and maintain a robust connection with your external API. Remember, proactive communication with your service provider and proper planning are the cornerstones of successful integrations.</p>
]]></content:encoded></item></channel></rss>