GHSA-7jvp-hj45-2f2m

Suggest an improvement
Source
https://github.com/advisories/GHSA-7jvp-hj45-2f2m
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/07/GHSA-7jvp-hj45-2f2m/GHSA-7jvp-hj45-2f2m.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-7jvp-hj45-2f2m
Aliases
Published
2026-07-06T17:30:17Z
Modified
2026-08-17T03:55:59Z
Severity
  • 7.7 (High) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N/E:P CVSS Calculator
Summary
Scriban: Template Writes to Arbitrary CLR Properties via `TypedObjectAccessor` (Mass Assignment + `private` / `init` / `internal` Setter Bypass)
Details

Description

When a host pushes a CLR object into a Scriban TemplateContext via the standard, documented pattern —

var so = new ScriptObject();
so["user"] = currentUser;   // direct CLR reference
context.PushGlobal(so);

TypedObjectAccessor exposes every public-getter property for both reading and writing, and writes land on the live host object and persist after Render() returns. The write path performs no CanWrite and no setter-visibility check, producing two related but distinct weaknesses:

(A) Mass assignment of public setters — CWE-915 (originally F-002). Any { get; set; } property is writable from template code ({{ user.is_admin = true }}, {{ order.total_price = 0 }}). This is "surprising but technically consistent with the setter being public" — and crucially, Scriban offers no way to expose such a property read-only, because MemberFilter is read/write-symmetric.

(B) Access-modifier bypass — CWE-284 (originally F-007). Properties the developer deliberately restricted are also writable, because reflection ignores C# accessibility:

Declaration Developer intent Actual behavior
{ get; set; } writable writable (mass assignment — A)
{ get; private set; } only the owning class writes template writes freely
{ get; internal set; } only the declaring assembly writes template writes freely
{ get; init; } immutable after construction (C# 9 language guarantee) template writes freely post-construction

The init-only post-construction write — the highest false-positive risk — was explicitly confirmed against the shipped 7.2.1 package.

Affected Versions

All releases that ship TypedObjectAccessor (<= 7.2.1). PrepareMembers has used the getter-only filter since the accessor was introduced, and TrySetValue has never checked the setter. The init bypass applies on .NET 5+; private set / internal set apply on every supported runtime. No patched version exists.

Steps to Reproduce

Copy-paste. Run from the engagement root (the folder containing both scriban/ and reports/).

Prereqs:

test -d scriban || { echo "scriban source missing"; exit 1; }
( command -v dotnet >/dev/null && dotnet --list-sdks | grep -q '^10\.' ) \
  || ( "$HOME/.dotnet/dotnet" --list-sdks | grep -q '^10\.' ) \
  || { echo ".NET 10 SDK missing"; exit 1; }
export PATH="$HOME/.dotnet:$PATH"

Run both PoCs (native):

( cd reports/f002/poc && dotnet run -c Release )   # (A) public-setter mass assignment
( cd reports/f007/poc && dotnet run -c Release )   # (B) private/internal/init bypass

Docker fallback (no native SDK required):

docker run --rm -v "$PWD":/work -w /work/reports/f007/poc \
  mcr.microsoft.com/dotnet/sdk:10.0 bash -lc "dotnet run -c Release"

Confirm the published package is affected (not just master): swap the ProjectReference in reports/f007/poc/poc.csproj for <PackageReference Include="Scriban" Version="7.2.1" /> and re-run — the four bypasses still succeed.

Each PoC prints [1] original CLR values, [2] template output (reads originals → writes → reads back), and [3] the C#-side read after Render() proving the live host object was permanently altered.

Remediation

Fixes are listed flat. Note that (B) has a clean, clearly-correct code fix; (A) requires a new control because public-setter writes are otherwise by-design.

  • Fix 1 — block restricted setters in TrySetValue (TypedObjectAccessor.cs L108–L123). Fixes (B). Before the L120 SetValue, require a public, non-init setter:
    var setM = propertyAccessor.GetSetMethod(nonPublic: false);
    if (setM is null) return false;   // private / internal / protected setters
    if (setM.ReturnParameter.GetRequiredCustomModifiers()
          .Any(m => m.FullName == "System.Runtime.CompilerServices.IsExternalInit"))
        return false;                 // init-only: setter IS public, so the IsExternalInit check is REQUIRED
    
    A plain GetSetMethod(nonPublic:false) != null check is not sufficient for init — the init setter is public; only the IsExternalInit modreq distinguishes it.
  • Fix 2 — give hosts a read/write distinction (addresses (A)). Add a MemberWriteFilter on TemplateContext (separate from MemberFilter) and/or a [ScriptMemberReadOnly] attribute, and split _members into _readableMembers / _writableMembers in PrepareMembers (L126–L186). Public-settable mass assignment cannot be blocked without one of these, because MemberFilter is read/write-symmetric today.
  • Fix 3 — restore read-only-by-default on ScriptObject.Import (ScriptObjectExtensions.cs L320–L324). Gate the Liquid-compatibility relaxation behind an explicit opt-in instead of removing write protection globally.
  • Fix 4 — documentation (site/docs/runtime/safe-runtime.md). State explicitly that templates can write CLR properties via reflection (including private/internal/init setters), and that MemberFilter does not separate read from write.
  • Fix 5 — regression tests (src/Scriban.Tests/). Assert private set / internal set / init are non-writable from templates, that MemberWriteFilter / [ScriptMemberReadOnly] gate writes, and that only public set is writable.

References

Database specific
{
    "cwe_ids": [
        "CWE-284",
        "CWE-915"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-07-06T17:30:17Z",
    "nvd_published_at": null,
    "severity": "HIGH"
}
References

Affected packages

NuGet / Scriban

Package

Name
Scriban
View open source insights on deps.dev
Purl
pkg:nuget/Scriban

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
7.2.2

Affected versions

0.*
0.1.0
0.2.0
0.2.1
0.2.2
0.3.0
0.3.1-pre028
0.3.1
0.4.0
0.5.0
0.6.0
0.7.0
0.9.0-pre100
0.9.0
0.9.1
0.10.0
0.11.0
0.12.0
0.12.1
0.13.0
0.14.0
0.15.0
0.16.0
1.*
1.0.0-beta-001
1.0.0-beta-002
1.0.0-beta-003
1.0.0-beta-004
1.0.0-beta-005
1.0.0-beta-006
1.0.0
1.1.0
1.1.1
1.2.0
1.2.1
1.2.2
1.2.3
1.2.4
1.2.5
1.2.6
1.2.7
1.2.8
1.2.9
2.*
2.0.0-alpha-001
2.0.0-alpha-002
2.0.0-alpha-003
2.0.0-alpha-004
2.0.0-alpha-005
2.0.0-alpha-006
2.0.0
2.0.1
2.1.0
2.1.1
2.1.2
2.1.3
2.1.4
3.*
3.0.0
3.0.1
3.0.2
3.0.3
3.0.4
3.0.5
3.0.6
3.0.7
3.1.0
3.2.0
3.2.1
3.2.2
3.3.0
3.3.1
3.3.2
3.3.3
3.4.0
3.4.1
3.4.2
3.5.0
3.6.0
3.7.0
3.8.0
3.8.1
3.8.2
3.9.0
4.*
4.0.0
4.0.1
4.0.2
4.1.0
5.*
5.0.0
5.1.0
5.2.0
5.3.0
5.4.0
5.4.1
5.4.2
5.4.3
5.4.4
5.4.5
5.4.6
5.5.0
5.5.1
5.5.2
5.6.0
5.7.0
5.8.0
5.9.0
5.9.1
5.10.0
5.11.0
5.12.0
5.12.1
6.*
6.0.0
6.1.0
6.2.0
6.2.1
6.3.0
6.4.0
6.5.0
6.5.1
6.5.2
6.5.3
6.5.4
6.5.5
6.5.6
6.5.7
6.5.8
6.6.0
7.*
7.0.0
7.0.1
7.0.2
7.0.3
7.0.4
7.0.5
7.0.6
7.1.0
7.2.0
7.2.1

Database specific

last_known_affected_version_range
"<= 7.2.1"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/07/GHSA-7jvp-hj45-2f2m/GHSA-7jvp-hj45-2f2m.json"