Skip to content

Validate all DHT records if a record validator exists #1070

@hayotensor

Description

@hayotensor

Description

What I'm proposing is we either force all DHT records to be put through the namespace validator, or create a bool variable such as strict_namespace_validator when initializing the KadDHT where if it's true, all records, put and get, will be validated no matter the format.

Motivation

For some networks, the ability to validate all records is essential. Many applications require strict control over which keys may be stored, whether for security, correctness, or protocol-level rules. If unvalidated keys can bypass custom logic, peers may end up storing arbitrary or malformed data that violates the network’s intended behavior.

By supporting validation for every record, implementations can:

  • Enforce permissioned keyspaces: Nodes can reject keys outside the allowed schema, key logic, or namespace.
  • Improve security: Prevent accidental or malicious insertion of unexpected data.
  • Ensure protocol correctness: Peers can enforce application-specific invariants (e.g., commit–reveal flows, unique key patterns, signed records).
  • Align closer with go-libp2p and rust-libp2p behavior (I believe)

Current Implementation

In the current implementation in put_value in kad_dht.py, the validator logic only triggers when a record has a "/" prepended to the record key.

Here's the line in question:

if key.decode("utf-8").startswith("/"):

Are you planning to do it yourself in a pull request ?

Maybe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions