Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source pure

Package nestedpkg provides helpers for package-path based access control. It is useful for upgrade patterns relying o...

Readme View source

gno.land/p/moul/nestedpkg

Access 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.

Security: why every helper takes rlm realm

A 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.

Overview

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.

Functions 6

func AssertCallerIsParentPath

1func AssertCallerIsParentPath(_ int, rlm realm)
source

AssertCallerIsParentPath panics if IsCallerParentPath returns false.

func AssertCallerIsSubPath

1func AssertCallerIsSubPath(_ int, rlm realm)
source

AssertCallerIsSubPath panics if IsCallerSubPath returns false.

func AssertIsSameNamespace

1func AssertIsSameNamespace(_ int, rlm realm)
source

AssertIsSameNamespace panics if IsSameNamespace returns false.

func IsCallerParentPath

1func IsCallerParentPath(_ int, rlm realm) bool
source

IsCallerParentPath checks if the caller realm is located in a parent location of the current realm.

func IsCallerSubPath

1func IsCallerSubPath(_ int, rlm realm) bool
source

IsCallerSubPath checks if the caller realm is located in a subfolder of the current realm.

func IsSameNamespace

1func IsSameNamespace(_ int, rlm realm) bool
source

IsSameNamespace checks if the caller realm and the current realm are in the same namespace.

Dependencies

Imports 1

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/nestedpkg/v0

Imported by indexer

Source Files 4