Skip to content

Let applications take over signature time validation #168

Closed

Description

@rosylilly

Use case

My ActivityPub server (mycroblog/my) accepts both RFC 9421 and draft-cavage signatures, and only RFC 9421 goes through httpsig. To keep one time policy for both schemes, the server checks the time window itself, before calling the library, using an injected clock. For RFC 9421 it rejects a signature when:

  • created is more than 1 hour in the future
  • expires, or created + 12 hours when there is no expires, passed more than 1 hour ago

Problem

WithMaxAge applies to created even when a signature has a later expires, so the library can't express this policy. WithCreatedTimestamp(false) and WithExpiresTimestamp(false) only make the parameters optional, and they are still checked when present. So I set WithMaxAge and WithValidityTolerance to 100 years to turn the checks off.

A correction to my PR comment: I framed this as a clock problem, but WithClock alone wouldn't remove this workaround. On the verification side, what I need is to turn the checks off.

Requirements

  1. An explicit way to disable the verifier's time checks. It should be hard to do by accident, since the application then owns this check completely.
  2. Lower priority: a time source for the signer. created comes from the system clock, while my server sets the Date header from its injected clock. Nothing is broken today, but both would ideally use the same source.

Possible shape

WithoutTimeValidation() as a VerifierOption, and WithClock(now func() time.Time) as a SignerOption. I'm happy to open a PR if you'd like this.

Activity

  1. dadrus commented on Nov 4, 2026

    @dadrus
    Owner

    I see. What do you think about introducing a WithoutMaxAge() option? It would disable the maximum age check based on created, while the library would still ensure that created is not in the future (within the configured tolerance). The expires check would also remain unchanged. Would that help?

  2. rosylilly commented on Nov 5, 2026

    @rosylilly
    ContributorAuthor

    WithoutMaxAge() works for me. The library would still check expires and a future created, and my server would keep its 12-hour limit for signatures without expires, so I no longer need WithoutTimeValidation().

    Separately, I'd still like to inject the time source, for tests, for verifying fixtures with fixed timestamps, and for keeping time in sync with another source such as the database. currentTime always follows the system clock, so when the application's time differs from it:

    • If the application's time is ahead, a freshly signed message fails with "signature not yet valid".
    • If it's behind, a signature with expires can fail with "signature expired", although it's still valid at the application's time.

    The library's own tests have the same need: they replace currentTime to verify the RFC 9421 test vectors, which code outside the package can't do.

    So how about adding WithClock for both sides?

    func WithClock(now func() time.Time) clockOption // VerifierOption and SignerOption
    
    verifier, err := httpsig.NewVerifier(
        resolver,
        httpsig.WithClock(clock.Now),
        httpsig.WithoutMaxAge(),
        httpsig.WithValidityTolerance(time.Hour),
        // ...
    )
    • On a verifier, it's the time source for the expires and created checks. A verifier has one clock, so using it inside WithRequiredTag is a construction error.
    • On a signer, it's the time source for created, and for expires when it's derived from created.
    • A nil function is a construction error.

    With both options, I could drop my 100-year WithMaxAge and WithValidityTolerance workaround. What do you think?

  3. dadrus commented on Nov 5, 2026

    @dadrus
    Owner

    Let's go with WithoutMaxAge first and address WithClock separately.

    Regarding WithClock: I just merged #183, which replaces the custom time patching used in our RFC test cases with testing/synctest, available since Go 1.25. Would this perhaps eliminate the need for WithClock? If not, could you please open a separate feature request for it? And feel free to submit a PR as well! :)

  4. rosylilly commented on Nov 6, 2026

    @rosylilly
    ContributorAuthor

    Thanks for #183! testing/synctest covers the test use case, so WithoutMaxAge is all I need for now. If I run into a production use case that really needs WithClock, I'll open a separate feature request then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions