Skip to content

feat(psl): add DAFSA-format Public Suffix List reader#215

Merged
AlfioEmanueleFresta merged 12 commits into
masterfrom
issue-210-dafsa-psl
May 18, 2026
Merged

feat(psl): add DAFSA-format Public Suffix List reader#215
AlfioEmanueleFresta merged 12 commits into
masterfrom
issue-210-dafsa-psl

Conversation

@AlfioEmanueleFresta
Copy link
Copy Markdown
Member

@AlfioEmanueleFresta AlfioEmanueleFresta commented May 12, 2026

Closes #210.

Adds a safe-Rust reader for libpsl's binary .dafsa PSL file and an auto-detecting SystemPublicSuffixList::auto() loader that probes .dafsa then .dat. Fixes the Fedora default-install gap where only .dafsa is shipped.

The DAFSA lookup is a port of LookupStringInFixedSet; format is described in psl-make-dafsa. No new runtime deps.

Test plan

  • CI passes (clippy + fmt + workspace tests) with the new `apt-get install publicsuffix` step
  • Gated integration test `psl::system::tests::system_psl_loads_and_resolves_common_suffixes` runs in CI (`LIBWEBAUTHN_PSL_SYSTEM_TEST=1`) against Debian's real PSL files
  • Verified locally on Fedora that `SystemPublicSuffixList::auto()` loads the system `.dafsa` and resolves IDN suffixes in punycode form (e.g. `xn--55qx5d.hk`)

@AlfioEmanueleFresta AlfioEmanueleFresta marked this pull request as ready for review May 14, 2026 18:16
@AlfioEmanueleFresta AlfioEmanueleFresta changed the title Add DAFSA-format Public Suffix List reader feat(psl): add DAFSA-format Public Suffix List reader May 17, 2026
Copy link
Copy Markdown
Collaborator

@msirringhaus msirringhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle ok. Some smaller nitpicks and questions, but ok as is.

Comment thread libwebauthn/src/ops/webauthn/psl/dafsa.rs Outdated
Comment thread libwebauthn/src/ops/webauthn/psl/dafsa.rs Outdated
Comment thread libwebauthn/src/ops/webauthn/psl/system.rs
Pure code move with no behavior change. Splits the single-file PSL module
into a directory layout to make room for additional reader implementations.
The trait and MockPublicSuffixList stay in mod.rs; DatFilePublicSuffixList
moves to dat.rs.
Adds a safe-Rust reader for libpsl's binary .dafsa file format. The reader
ports LookupStringInFixedSet from libpsl's lookup_string_in_fixed_set.c
(BSD-licensed by The Chromium Authors), translating the byte-coded DAFSA
walk to safe Rust without unsafe or extra dependencies.

Closes the Fedora gap from issue #210: Fedora ships only the .dafsa file
by default (via publicsuffix-list-dafsa, which libpsl requires).

Tests cover plain rules, wildcard, exception, private section, and the
file-header parser edge cases. The fixture was generated by libpsl's
psl-make-dafsa script from a small synthetic PSL.
Auto-detects which system-managed PSL file is available, preferring
.dafsa over .dat. Returns SystemLoadError::NoneFound listing the paths
tried if neither is present.

Includes an integration test gated by LIBWEBAUTHN_PSL_SYSTEM_TEST=1 that
loads the real system PSL and validates lookups against common suffixes.
The gating env var is intentional so that local 'cargo test' runs do not
require any package to be installed.
Switches the three ceremony examples (cable, hid, nfc) to the
auto-detecting loader so they work out of the box on Fedora (where only
.dafsa is shipped) and on Debian/Ubuntu/Arch.

Also re-exports the new public types (SystemPublicSuffixList,
DafsaFilePublicSuffixList, etc.) from ops::webauthn alongside the
existing DatFilePublicSuffixList for callers wiring the list themselves.
Updates the Runtime requirements section to reflect that the loader now
auto-detects the .dafsa format alongside .dat, and explains which package
ships which format on each distribution.
apt-get installs Debian's publicsuffix package (ships both .dat and
.dafsa). Sets LIBWEBAUTHN_PSL_SYSTEM_TEST=1 on the test step so the
SystemPublicSuffixList::auto() integration test runs against the real
system file in CI.
Crate denies clippy::expect_used outside tests; the version parse now
propagates BadMagic on UTF-8 failure even though the bytes were already
validated as ASCII digits. Also rustfmt reflow of test code.
Module docs now call out the two intentional deviations from libpsl's
psl_is_public_suffix: no prevailing-star rule for unknown single-label
TLDs (so localhost works as its own rp.id), and no multibyte key
support (WebAuthn only ever passes IDN-ASCII, and the DAFSA stores IDN
rules in punycode form regardless of encoding mode). Test comment for
the exception-overrides-wildcard case rewritten to describe the actual
lookup chain rather than conflating two mechanisms.
Replace the raw graph indexing and the over-strict `*pos + 2 >= end`
guard with .get() lookups and checked_add for the offset accumulator.
The old guard rejected structurally-valid 1- and 2-byte offset codes at
the end of the graph and could overflow usize on `*pos + 2`; the new
form is panic-free by construction and accepts those codes.
DafsaFilePublicSuffixList and MockPublicSuffixList had byte-identical
registrable_domain impls expressed purely in terms of public_suffix.
Move that body to a default method on PublicSuffixList; DatFilePublicSuffixList
keeps its override (it uses the publicsuffix crate's own root()).
Add a module-scoped deny(clippy::indexing_slicing) for non-test code,
mirroring the crate-wide lint planned in #207, as an interim guard.

Replace the remaining panic-capable slice indexing in parse_header,
is_public_suffix and public_suffix with split_at_checked, starts_with,
last, .get() and split_once. Behaviour is unchanged (verified by the
existing unit tests and the gated system-file test).
@AlfioEmanueleFresta AlfioEmanueleFresta merged commit 16be38a into master May 18, 2026
@AlfioEmanueleFresta AlfioEmanueleFresta deleted the issue-210-dafsa-psl branch May 18, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a DAFSA-format Public Suffix List reader

2 participants