func AssertCallerIsParentPath
AssertCallerIsParentPath panics if IsCallerParentPath returns false.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Package nestedpkg provides helpers for package-path based access control. It is useful for upgrade patterns relying o...
gno.land/p/moul/nestedpkgAccess control by package path. Instead of "is the caller this address", ask "is the caller inside my namespace, below me, or above me in the tree".
1func IsCallerSubPath(_ int, rlm realm) bool
2func IsCallerParentPath(_ int, rlm realm) bool
3func IsSameNamespace(_ int, rlm realm) bool
4
5func AssertCallerIsSubPath(_ int, rlm realm) // panics instead
6func AssertCallerIsParentPath(_ int, rlm realm)
7func AssertIsSameNamespace(_ int, rlm realm)
Each helper compares rlm.PkgPath() with rlm.Previous().PkgPath():
| helper | true when the caller is |
|---|---|
IsCallerSubPath |
below the current realm (r/moul/app/sub calling r/moul/app) |
IsCallerParentPath |
above it (r/moul/app calling r/moul/app/sub) |
IsSameNamespace |
under the same r/<user> prefix |
That is what makes upgrade patterns work: r/moul/app/v2 can be allowed to
read r/moul/app/v1's state without either version knowing the other's
address, because the namespace is the credential.
rlm realmA realm value can be captured and stashed. A hostile realm that kept one from
an earlier call could hand it back later to impersonate the path it names.
Every helper here gates on rlm.IsCurrent() first, before reading any
path, which closes that forgery: the value must be the live one for this call.
The two families fail differently, on purpose:
Is* returns false on a stale rlm (fail closed, so a check cannot be
turned into a pass by replaying an old value);Assert* panics.The leading _ int parameter is unused (_). Pass 0.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.
Package nestedpkg provides helpers for package-path based access control. It is useful for upgrade patterns relying on namespaces.
SECURITY: every exported helper takes `rlm realm` and reads both `rlm.PkgPath()` and `rlm.Previous().PkgPath()` to make an authorization decision. To close Class-2 designation forgery (a hostile realm stashes a captured realm value and passes it back to spoof identity), every helper gates on `rlm.IsCurrent()` first. The Is* predicates return false on stale rlm (fail-closed); the Assert* helpers panic. See docs/resources/gno-security.md.
AssertCallerIsParentPath panics if IsCallerParentPath returns false.
AssertCallerIsSubPath panics if IsCallerSubPath returns false.
AssertIsSameNamespace panics if IsSameNamespace returns false.
IsCallerParentPath checks if the caller realm is located in a parent location of the current realm.
IsCallerSubPath checks if the caller realm is located in a subfolder of the current realm.
IsSameNamespace checks if the caller realm and the current realm are in the same namespace.