Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

Arbitrary code execution in Mustache for Ruby: the fix in 1.1.3

Table of contents · 6 items

Some business systems let users or operations staff edit email text, forms, and notification wording from the screen. If that mechanism uses Mustache, known as a "logic-less template" language, it seems safe to leave template writing to them. The advisory itself notes that Mustache "is often recommended as a safe, simple template language for avoiding SSTI (server-side template injection)."

On November 18, 2026, an advisory (GHSA-5hrj-7fc3-cmx9, CVE-2026-130001, CRITICAL) stating that anyone who can write a template string can execute arbitrary code with the application's privileges in the Ruby version of Mustache (the gem mustache) was added to GitHub's advisory database. The same advisory had been published in the mustache repository on August 20, the same day as the fixed version 1.1.3. Versions 1.1.2 and earlier are affected. In this article, we use the advisory and the fix code to outline which usages are affected, and present the results of checking in a test environment whether existing templates render differently with 1.1.3.

It applies when templates can be written from outside

According to the advisory, 1.1.2 and earlier did not sufficiently restrict which methods could be called from templates, and arbitrary code could be executed by chaining built-in methods. The advisory states the following explicitly.

  • Exploitation does not depend on the settings or objects passed to the template. If the template string can be manipulated, arbitrary code can be executed with no other conditions
  • If the application or gems add methods, the range usable in an attack widens further
  • In addition to arbitrary code execution, the reporter confirmed execution via file upload, denial of service by exhausting memory, and denial of service by causing indefinite waits

The version added to the database contained limited information to allow time for updates, and said proof-of-concept code (PoC) would be added later. Subsequently, the repository advisory was updated on November 19 to include PoC templates. Each one, like {{#class.class.superclass…}}, chains reflection methods (features that let an object inspect its own class and internals) such as class, superclass, subclasses, and included_modules to reach classes that were never passed to the template. Alongside an example of arbitrary code execution on Ruby 3.3 and later, there are examples of reading files, executing uploaded files, waiting indefinitely, and exhausting memory. Now that attack steps are public, systems that still run 1.1.2 or earlier and let users write templates need to be updated immediately.

On the other hand, if only developers write templates and they are kept in the repository, users cannot change the template strings. Whether you are affected depends on whether users can edit the template string itself through screens, admin features, or the database. If users can only enter the values that get inserted (such as customer names), the advisory's conditions do not apply. However, building a template string by concatenating user input is the same as letting users write templates.

The five levels of restriction added in 1.1.3

The fix adds a setting, context_access_security_level, that restricts method calls from templates (commits 6f0b0a2 and 2bf0a2c, included in 1.1.3). According to the code's documentation, it has the following five levels.

StageWhat is allowed
1All methods (use only for trusted templates)
2 (default)Blocks reflection-related methods with a denylist
3Prohibits inherited methods and reflection-related methods
4Hash entries only
5Hash entries only. Values are also limited to numbers, strings, hashes, and functions (partially implemented, according to the code comments)

The level 2 denylist contains 93 method names, including class, send, instance_eval, instance_variable_get, define_method, and const_get. The superclass, subclasses, and included_modules used by the PoC above are also on this list. By default, violations are treated as empty, and an exception (Mustache::ContextLevelViolation) is raised only when raise_on_context_miss is enabled.

Do existing templates change? (checked in a test environment)

To see whether ordinary templates render differently after upgrading to 1.1.3, we installed 1.1.2 and 1.1.3 separately on Ruby 3.3.6 in a Linux (x86_64) test environment (November 19, 2026). Rather than reproducing the attack, we rendered five templates that use a hash, a method on a custom class, attr_reader, Integer's to_s, and a method on the denylist.

Table comparing the rendering results of five templates in Mustache for Ruby 1.1.2 and 1.1.3. A hash value, a method on a custom class, attr_reader, and Integer's to_s gave the same results in 1.1.2 and in 1.1.3 at the default (level 2) and level 3, while class became empty in 1.1.3. At level 4, only the hash value was displayed

The results were as follows.

  • At the 1.1.3 default (level 2), ordinary templates gave the same results. The hash's {{name}}, the object's {{customer.name}}, {{total}} of attr_reader, and Integer's {{to_s}} returned the same strings as in 1.1.2.
  • Methods on the denylist became empty. {{class}} returned String in 1.1.2 and was empty in 1.1.3.
  • At level 4, places that use object methods became empty. Only the hash values were displayed, and {{customer.name}}様 was reduced to just the honorific "sama." Level 3 gave the same results as the default for these five examples. Level 3 blocks methods that the value's own class does not define. to_s was not blocked because Integer's own class defines it. We did not test templates that call methods inherited from a parent class.

For features where users can write templates, the editorial team considers it safe to raise the level to 4 or 5 and make all values passed to templates hashes. In that case, existing templates that rely on object methods will have missing output, so you will need to rework the code to pass values as hashes.

Steps to check (editorial suggestion)

  1. Check the gem version. Check the version with bundle exec gem list mustache or Gemfile.lock. If it is 1.1.2 or earlier, upgrade to 1.1.3. It may also be installed as a dependency of another gem, so check what pulls it in with bundle exec gem dependency or similar.
  2. Identify where templates come from. Look for places that load templates from a database or admin screen and pass them to Mustache.render. If templates come only from files in the repository, the impact is small; if users can edit them, fix those first.
  3. Raise the level for user-written templates. Configure it as in Mustache.context_access_security_level = 4, and make the values passed to templates hashes. As far as we can tell from reading the 1.1.3 code (settings.rb), view classes that inherit from Mustache initialize their own setting to level 2 when created. So if you use view classes, set it on those classes as well (the editorial team has not verified this by running it). If you want to log violations, enable raise_on_context_miss. Because Mustache::ContextMiss is also raised for keys that do not exist, catch violations separately with the subclass Mustache::ContextLevelViolation.
  4. Compare rendering after updating. Render your main templates before and after the update and check that nothing has become empty.

We covered how to identify affected Ruby apps after a regular expression fix in our article on the Ruby regular expression fix, and the thinking behind pinning dependency updates in our article on Dependabot.

Scope of verification

On November 19, 2026, we checked the JSON for GHSA-5hrj-7fc3-cmx9 (published November 18, 2026) in github/advisory-database, commits 6f0b0a2, 2bf0a2c, bb646c7, and b015f86 (1.1.3) and HISTORY.md in mustache/mustache, lib/mustache/settings.rb, context.rb, and context_miss.rb, and the publication dates of each version on RubyGems.org (document research). We also installed mustache 1.1.2 and 1.1.3 on Ruby 3.3.6 in a Linux (x86_64) test environment and compared five templates rendered at the default and at levels 2–4 (hands-on testing). On November 20, we rechecked the mustache/mustache advisory (published August 20, updated November 19, retrieved via the GitHub API) and the 1.1.3 code. No version newer than 1.1.3 has been released. We have not reproduced the attack. We have not checked other gems that use Mustache, behavior on frameworks such as Rails, setting the level on view classes, the exception when raise_on_context_miss is enabled, or the behavior of level 5.

For designing user-editable templates or reviewing dependencies in business systems, please contact us through Development, AI, and automation consultations.

References

Share this articleXFacebook
Kakeru Suzuki

Fascinated by the possibilities of technology, has had a deep interest in programming and digital art since student days

Turn this article's theme into your company's next step

Concrete steps forward for your organization.

We organize your desired architecture, legacy systems, and operational requirements to formulate your next steps toward execution.

  • Desired architecture
  • Integration with existing environments
  • Operational requirements
Consult on development & operations initiatives

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles by email