privfield

package
v1.35.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package privfield provides serializer-layer field-level privacy redaction. It composes with internal/privctx (row-level tier stamping) but operates one level lower: on a single field within an already-admitted row.

Use Redact at each API surface's response-assembly site, passing the pre-existing <field>_visible companion string stored on the ent row. Every surface MUST call Redact for every field guarded by a _visible companion. There is no centralized enforcement. Each serializer calls Redact, and the 5-surface end-to-end test locks this.

Design rationale:

  • redaction happens at the serializer layer, not via an ent Policy, because ent's Privacy operates at the query/row level only.
  • it lives in this reusable package so every surface shares one implementation.
  • it fails closed on an unstamped ctx (the most restrictive tier).
  • it signals omission so the caller can drop the field entirely (callers rely on json omitempty for absence on the wire).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redact

func Redact(ctx context.Context, visible, value string) (out string, omit bool)

Redact returns (value, false) if the caller's tier on ctx admits the field, or ("", true) if the serializer should omit the field entirely.

Admission rule: admit when visible is in the caller tier's privctx.Tier.AdmittedVisibilities, the same set that the row gates use. That gives:

  • visible == "Public" → always admit (any tier)
  • visible == "Users" && tier Users+ → admit
  • visible == "Users" && tier Public → redact (the gated case)
  • visible == "Private" → redact in all tiers (upstream parity)
  • any unrecognized visible value → redact (fail-closed)

Fail-closed semantics: privctx.TierFrom(ctx) already returns TierPublic for un-stamped contexts, so an un-plumbed ctx naturally lands in the most restrictive branch — no extra check needed here.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL