{
  "id": 22494724,
  "title": "A vs B: Placing Your WAF Before or After a JSON API Gateway",
  "url": "https://urgent.news/2026/11/29/a-vs-b-placing-your-waf-before-or-after-a-json-api-gateway",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-29T02:08:01.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/_eb0609572b9efcf27472066/a-vs-b-placing-your-waf-before-or-after-a-json-api-gateway-24ap"
  },
  "original_language": null,
  "account": "When designing a security strategy to protect against SQL injection attacks that exploit JSON bodies, the placement of a Web Application Firewall (WAF) becomes crucial. Two common deployment strategies are examined: inspecting JSON payloads before the API gateway (Option A) or after the gateway has transformed the request (Option B). Each placement offers distinct advantages and considerations depending on the specific deployment context and requirements.\n\nIn Option A, where inspection occurs before the API gateway, the WAF acts as the first layer of defense. The request, including its JSON payload, passes through the WAF where it can be examined for suspicious patterns indicative of an SQL injection attempt. This placement is beneficial when the API gateway itself is exposed to the internet or when multiple downstream APIs share a common entry point. By filtering requests at the WAF level, the application is shielded from potentially harmful traffic before it reaches the gateway. However, it's essential to note that if the API gateway transforms the request body, for instance, altering the JSON structure or altering content, this can create a discrepancy between the request inspected by the WAF and the one forwarded to the application. Consequently, there is a risk of missing some injection attempts, as the transformation could lead to a request that the WAF does not recognize as malicious.\n\nOption B, on the other hand, places the WAF after the API gateway, meaning the request has already been transformed by the gateway before it encounters the WAF. This placement can be advantageous when the gateway performs necessary transformations, such as converting incoming data into a format expected by the application. Inspecting after the gateway ensures that the application receives requests in the format they are designed to handle, reducing the likelihood of misinterpretation or errors. However, this approach increases the attack surface because the WAF must defend against attacks on all entry points, including internal and administrative endpoints. Additionally, any security controls placed at this stage must be robust enough to handle the transformed data and ensure that legitimate traffic is not inadvertently blocked.\n\nIn both scenarios, it's vital to conduct thorough testing. Authorized tests should be run against a staging environment, simulating a wide range of legitimate and malicious payloads, including nested JSON structures, malformed JSON, and various encoding techniques. The outcomes of these tests should be meticulously recorded, focusing on three key areas: the decision made by the WAF, whether the application successfully received the request, and the actions taken by the application with the received data. While the presence of blocked responses indicates successful detection, it does not guarantee comprehensive coverage of all possible injection vectors or transformations.\n\nThe official documentation of SafeLine, a self-hosted WAF, outlines its capabilities in filtering HTTP traffic, including protection against SQL injection attacks. However, it does not specify whether SafeLine inspects nested JSON bodies or decodes JSON data to a certain depth. As such, validating the deployment of SafeLine within your specific environment becomes crucial. This includes confirming the WAF's behavior regarding JSON parsing, ensuring that authentication contexts are preserved during request transformations, and verifying that client identities are accurately propagated to downstream systems for effective attribution and policy enforcement.\n\nUltimately, the choice between inspecting JSON payloads before or after an API gateway should be based on a comprehensive evaluation of the deployment environment, the specific security needs of the application, and the thoroughness of testing performed. Regardless of the chosen placement, implementing strict security practices, such as utilizing parameterized queries and explicitly allowing safe identifiers in dynamic queries, remains paramount in mitigating the risk of SQL injection attacks through JSON payloads.",
  "summary": "An automated attacker does not need a suspicious URL to probe for SQL injection. A normal-looking POST to a search endpoint can carry the payload inside a JSON filter, nested object, or array. If the application builds SQL by concatenating that value, the request body becomes a route to the database. For security owners investigating how to block sql injection attempts hidden in json bodies,…",
  "summary_source": "publisher",
  "key_points": [
    "Option A places WAF before API gateway, inspecting JSON payloads first",
    "Option B places WAF after API gateway, after request transformation",
    "Testing required for both placements, focusing on WAF decisions and application actions"
  ],
  "editors_take": "Choosing where to place a firewall affects whether security tools catch malicious code or miss threats hidden by data transformations made by the gateway.",
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}