3. Write Policy Engine & Grant Enforcement
Nostr relays facing public networks require strict filtering to defend against denial-of-service attacks, spam flooding, invalid cryptographic claims, and timestamp spoofing.
fleetmesh-strfry implements a comprehensive policy enforcement engine (StrfryPolicyEngine) that acts as both an internal validation pipeline and an external strfry write-policy plugin.
3.1. The strfry Plugin Protocol
[strfry write-policy plugins](https://github.com/hoytech/strfry/blob/master/docs/plugins.md) communicate with the strfry relay daemon over standard input and standard output using a line-oriented JSON protocol:
strfry Relay Daemon fleetmesh-strfry plugin
─────────────────── ───────────────────────
{"type": "lookahead", ...} ───► (optional cache prep)
{"type": "new", "event": {"id": ...}} ───►
◄─── {"id": "...", "action": "accept"}
or {"id": "...", "action": "reject", "msg": "blocked: ..."}
or {"id": "...", "action": "shadowReject"}
3.1.1. Configuring strfry to Use the Plugin
In strfry.conf, configure the writePolicy block to invoke the fleetmesh_strfry plugin runner:
relay {
writePolicy {
plugin = "/usr/bin/env PYTHONPATH=/opt/fleetmesh/strfry-bridge:/opt/fleetmesh/meshnode:/opt/fleetmesh/core:/opt/fleetmesh/schema python3 -m fleetmesh_strfry plugin --dir /var/lib/fleetmesh"
}
}
When strfry starts, it spawns this subprocess. For every submitted event, strfry streams the event JSON to the plugin’s stdin, and the plugin returns its verdict on stdout.
3.2. Policy Verification Pipeline
The StrfryPolicyEngine evaluates every submitted event through a sequence of validation gates:
Validation Gate |
Description |
|---|---|
Event ID Recomputation |
Computes the SHA-256 hash of the canonical NIP-01 serialized event array |
Cryptographic Signature |
Verifies the 64-byte Schnorr signature (Secp256k1) against the author’s public key. |
Clock Skew Enforcement |
Compares |
NIP-40 Expiration |
Evaluates |
Payload Size Limits |
Rejects any event exceeding |
Kind Whitelisting & Blacklisting |
Enforces |
Rate Limiting |
Tracks sliding-window submission velocity per pubkey, capping submissions at |
3.3. Bilateral Peering Grant Enforcement
A unique capability of fleetmesh-strfry is bilateral peering grant enforcement. In a private or federated mesh deployment, an operator may wish to restrict relay storage solely to authorized peering partners holding active capacity grants.
When enforce_grants: true is configured:
The policy engine queries the node’s SQLite grant store (
grants.sqlite).It checks whether the author’s
pubkeymatches an active, unexpired peering grant (Kind 30801).If no active grant exists for that identity, or if the peer has exceeded their agreed bandwidth credit ceiling, the event is rejected:
{"id": "...", "action": "reject", "msg": "blocked: author has no active peering grant"}
3.4. Shadow Rejections
To analyze spam patterns without alerting malicious actors, the engine supports shadow_reject: true. In shadow mode, the relay responds to the client with an OK confirmation, but internally drops the event from LMDB storage, preserving disk space and downstream bandwidth.
3.5. Egress Policy
In addition to filtering inbound events entering strfry, the engine provides symmetric egress filtering:
Inspects events generated by the local node before publishing them out to the strfry relay.
Can redact sensitive internal telemetry tags or drop restricted kinds, ensuring that private mesh communications never leak onto public relays unintentionally.