Skip to content

[Security] Code Injection via Unescaped Custom Delimiters in Compiler (CWE-94) #284

Description

@ByamB4

Hi,

I found a code injection vulnerability in hogan.js that allows arbitrary code execution when compiling templates with crafted custom delimiters.

Affected: hogan.js <= 3.0.2 (all versions)
Severity: HIGH 8.1 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H)
CWE: CWE-94 (Improper Control of Generation of Code)

Root Cause: The esc() function in lib/compiler.js is applied to variable names (esc(node.n)), partial names (esc(sym)), and text (esc(node.text)) to prevent string-literal breakout in generated code. However, custom delimiters (node.otag, node.ctag) are embedded raw at line 332:

// Line 332 - NOT escaped
',"' + node.otag + " " + node.ctag + '")){' +

Custom delimiters can be set inline via standard Mustache {{=OTAG CTAG=}} syntax. A ctag containing " breaks out of the string literal, injecting arbitrary JS into the new Function() call at line 293.

Fix: Apply esc() to delimiter values:

',"' + esc(node.otag) + " " + esc(node.ctag) + '")){' +

I have a full PoC available. Since private vulnerability reporting is not enabled on this repo, I'm filing this as an issue. I would appreciate a GitHub Security Advisory for CVE tracking.

Researcher: Byambadalai Sumiya
GitHub: @ByamB4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions