{"id":27854869,"url":"https://github.com/genaker/cloudflare-nodejs-api-gateway","last_synced_at":"2026-02-19T14:06:07.124Z","repository":{"id":274903709,"uuid":"924418971","full_name":"Genaker/Cloudflare-NodeJS-API-Gateway","owner":"Genaker","description":"Cloudflare Worker API Proxy Gateway for Magento (Node.js)","archived":false,"fork":false,"pushed_at":"2025-01-31T21:54:48.000Z","size":21,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-22T13:13:48.200Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Genaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-30T00:47:09.000Z","updated_at":"2025-11-04T17:38:58.000Z","dependencies_parsed_at":"2025-05-04T09:59:40.210Z","dependency_job_id":"99c5ba59-fd41-42d6-9799-2b80cbd1f845","html_url":"https://github.com/Genaker/Cloudflare-NodeJS-API-Gateway","commit_stats":null,"previous_names":["genaker/cloudflare-magento-2-api-gateway","genaker/cloudflare-nodejs-api-gateway"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Genaker/Cloudflare-NodeJS-API-Gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FCloudflare-NodeJS-API-Gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FCloudflare-NodeJS-API-Gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FCloudflare-NodeJS-API-Gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FCloudflare-NodeJS-API-Gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Genaker","download_url":"https://codeload.github.com/Genaker/Cloudflare-NodeJS-API-Gateway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FCloudflare-NodeJS-API-Gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29616961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T13:04:20.082Z","status":"ssl_error","status_checked_at":"2026-02-19T13:03:33.775Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-04T09:59:35.578Z","updated_at":"2026-02-19T14:06:07.107Z","avatar_url":"https://github.com/Genaker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Cloudflare 2 API Gateway Worker**\n\nA **Cloudflare Worker** to secure and optimize API requests to a **Magento 2 store**. This worker:\n- ✅ **Blocks unauthorized API requests** (requires `CF-API-Secret` header).\n- ✅ **Implements rate limiting** to prevent abuse.\n- ✅ **Restricts access** to whitelisted API endpoints.\n- ✅ **Forwards allowed requests** to the Magento API.\n\n---\n\n## ** Supported Platforms**\n - Magento 1-2 and forks\n - WordPress\n - Shopify\n - ORO Commerce\n - Word Press\n - Shopware 6\n - Sylius\n - ODO\n - other platforms\n   \n---\n\n\n## **🚀 Features**\n| Feature | Status |\n|---------|--------|\n| **Blocks unauthorized API requests** | ✅ Implemented |\n| **Requires `CF-API-Secret` header** | ✅ Implemented |\n| **Enforces rate limiting per IP** | ✅ Implemented |\n| **Whitelists specific API endpoints** | ✅ Implemented |\n| **Prevents Magento API abuse** | ✅ Implemented |\n\n---\n\n## **📌 How It Works**\n1. **Intercepts API requests** before they reach Magento.\n2. **Checks the `CF-API-Secret` header** for authentication.\n3. **Validates API paths** to prevent unauthorized access.\n4. **Implements rate limiting** per IP.\n5. **Forwards valid requests** to Magento's API.\n\n---\n\n## **📁 Deployment Guide**\n### **1️⃣ Deploy the Worker in Cloudflare**\n1. **Go to Cloudflare Dashboard** → **Workers \u0026 Pages**.\n2. Click **Create Application** → **Create Worker**.\n3. Replace the default script with the worker (below).\n\n---\n\n### **2️⃣ Configure Environment Variables**\n| **Variable**       | **Default Value** | **Description** |\n|-------------------|----------------|----------------|\n| `MAGENTO_API_URL` | `\"https://default-magento-store.com/rest/V1/\"` | Magento API base URL. |\n| `MAGENTO_API_KEY` | `\"default-api-key\"` | Magento API authentication key. |\n| `WORKER_SECRET` | `\"12345\"` | Required `CF-API-Secret` header value. |\n| `IP_LIMIT` | `10` | Max API requests per IP per time window. |\n| `IP_WINDOW` | `60` | Time window (seconds) for rate limiting. |\n| `ALLOWED_PATHS` | `[\"carts/mine\",\"customers/me\",\"products\",\"orders\",\"categories\",\"payment-information\"]` | Whitelisted API endpoints. |\n\n---\n\n## **📝 Worker Code**\nCreate a file named **`worker.js`** and paste the  code from this repo \n---\n\n## **📌 Testing the Worker**\n### **❌ Unauthorized Request (Blocked)**\n```sh\ncurl -X GET \"https://your-worker.cloudflare.com/rest/V1/orders\"\n```\n🔴 **Response:**\n```json\n{\n    \"message\": \"403 Forbidden: API access denied\"\n}\n```\n\n---\n\n### **✅ Authorized Request (Allowed)**\n```sh\ncurl -X GET \"https://your-worker.cloudflare.com/rest/V1/orders\" -H \"CF-API-Secret: 12345\"\n```\n🟢 **Response:**  \n- **Forwards request** to Magento API.\n- **Returns Magento API response**.\n\n---\n\n## **🚀 Deployment \u0026 Activation**\n1️⃣ **Deploy the Worker**\n```sh\nwrangler deploy\n```\n\n2️⃣ **Set Up Environment Variables in Cloudflare**\n- **Go to Cloudflare Dashboard** → **Workers \u0026 Pages**.\n- **Click Settings** → **Add Environment Variables**.\n- Add:\n  ```\n  MAGENTO_API_URL = \"https://your-magento-store.com/rest/V1/\"\n  MAGENTO_API_KEY = \"your-secure-api-key\"\n  WORKER_SECRET = \"super-secret-key\"\n  ```\n\n3️⃣ **Activate Worker on Your Domain**\n- **Go to Cloudflare Dashboard** → **Workers \u0026 Pages**.\n- **Set Worker Route:**  \n  ```\n  https://your-worker.cloudflare.com/rest/*\n  ```\n\n---\n\n## **🛡️ Security Recommendations**\n- **Change the `WORKER_SECRET` regularly**.\n- **Limit API paths to prevent excessive exposure**.\n- **Enable rate limiting to prevent API abuse**.\n\n---\n\n# **Magento 2 API Access Control Using Cloudflare Snippet**\n\n## **🚀 Overview**\nThis repository contains a **Cloudflare Snippet** that **secures Magento 2 API access** by enforcing authentication through a custom **`CF-API-Secret`** header. It ensures that only authorized requests can access **Magento REST API endpoints**.\n\n## **🔒 Security Features**\n- ✅ **Blocks unauthorized API requests** unless they include the correct `CF-API-Secret` header.\n- ✅ **Works at the Cloudflare edge**, preventing unauthorized access before reaching the Magento server.\n- ✅ **Lightweight and efficient**, with no impact on Magento’s backend.\n- ✅ **Can be combined with additional security headers**.\n\n---\n\n## **📁 Installation \u0026 Deployment**\n### **1️⃣ Create a Cloudflare Snippet**\n1. **Go to Cloudflare Dashboard** → Select your domain.\n2. Click **Rules** → **Snippets**.\n3. Click **Create Snippet**.\n4. Name the snippet: **Magento API Security**.\n5. Paste the code from [`snippet.js`](#-snippetjs) below.\n6. **Set the snippet rule** to apply to:\n   ```\n   (http.request.full_uri wildcard \"*sub.domain.com/rest/*\")\n   ```\n7. **Save \u0026 Deploy**.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenaker%2Fcloudflare-nodejs-api-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenaker%2Fcloudflare-nodejs-api-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenaker%2Fcloudflare-nodejs-api-gateway/lists"}