X Tutup
Skip to content

Handle unverified inbound activities#611

Merged
dahlia merged 8 commits intofedify-dev:mainfrom
dahlia:on-unverified-activity
Mar 10, 2026
Merged

Handle unverified inbound activities#611
dahlia merged 8 commits intofedify-dev:mainfrom
dahlia:on-unverified-activity

Conversation

@dahlia
Copy link
Member

@dahlia dahlia commented Mar 9, 2026

Summary

Fixes #472

This PR adds InboxListenerSetters.onUnverifiedActivity() so applications can inspect inbound activities whose signatures could not be verified and optionally return a custom response instead of falling back to the default 401 Unauthorized behavior.

It also introduces detailed HTTP signature verification results so callers can distinguish unsigned requests, invalid signatures, and signing-key fetch failures without weakening the existing guarantee that normal inbox listeners only receive verified activities.

What changed

  • Added InboxListenerSetters.onUnverifiedActivity() and the related public types UnverifiedActivityHandler and UnverifiedActivityReason in packages/fedify/src/federation/.
  • Added verifyRequestDetailed() and the related public types VerifyRequestDetailedResult, VerifyRequestFailureReason, and FetchKeyErrorResult in packages/fedify/src/sig/.
  • Extended key-fetch failure reporting so higher-level code can inspect failed HTTP responses via FetchError.response in packages/vocab-runtime/src/request.ts.
  • Preserved existing negative key-cache behavior and activitypub.fetch_key tracing while exposing detailed HTTP-signature failure information.
  • Added OpenTelemetry attributes for HTTP-signature failure reasons and key-fetch failure details, and surfaced them through FedifySpanExporter in packages/fedify/src/otel/.
  • Updated the documentation in docs/manual/inbox.md and docs/manual/opentelemetry.md.
  • Added changelog entries in CHANGES.md.

@issues-auto-labeler issues-auto-labeler bot added activitypub/interop Interoperability issues component/federation Federation object related component/inbox Inbox related component/signatures OIP or HTTP/LD Signatures related labels Mar 9, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the handling and observability of inbound activities within the Fedify framework, specifically focusing on signature verification. It provides developers with finer-grained control over how unverified activities are processed, moving beyond a simple rejection to allow for custom responses based on the specific reason for verification failure. Concurrently, it improves debugging capabilities by exposing detailed failure reasons through both API return types and OpenTelemetry tracing, ensuring that applications can react intelligently to various network and security-related issues during activity processing.

Highlights

  • Custom Handling for Unverified Activities: Introduced Federatable.onUnverifiedActivity() which allows applications to inspect inbound activities whose signatures could not be verified and optionally return a custom HTTP response instead of the default 401 Unauthorized. This is particularly useful for scenarios like handling Delete activities from actors whose signing keys are no longer available (e.g., 404 Not Found or 410 Gone).
  • Detailed HTTP Signature Verification Results: Added verifyRequestDetailed() and related public types (VerifyRequestDetailedResult, VerifyRequestFailureReason, FetchKeyErrorResult) to provide more granular information about why HTTP signature verification failed. This enables callers to distinguish between unsigned requests, invalid signatures, and failures during key fetching.
  • Enhanced OpenTelemetry Tracing: Extended OpenTelemetry spans and events to expose detailed HTTP signature failure reasons and key-fetch failure details for inbound activities. This includes attributes like http_signatures.failure_reason, http_signatures.key_fetch_status, and http_signatures.key_fetch_error, which are also surfaced through FedifySpanExporter.
  • Improved Fetch Error Reporting: Added an optional FetchError.response property to @fedify/vocab-runtime's FetchError class. This allows higher-level APIs to inspect the original failed HTTP response when remote document or key fetches return an HTTP error, providing more context for debugging and custom handling.
Changelog
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Add Federatable.onUnverifiedActivity() so applications can
inspect inbound activities whose signatures could not be
verified without weakening the existing guarantee that inbox
listeners only receive verified activities.

Expose detailed HTTP signature failure reasons and key-fetch
results, preserve key-cache and fetch-key tracing behavior, and
surface the new verification details through OpenTelemetry span
data and FedifySpanExporter records.

Update the manual and changelog entries and add regression tests
covering malformed signatures, deleted-key retries, cached
unavailable keys, and telemetry output.

Fixes fedify-dev#472

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia force-pushed the on-unverified-activity branch from 1846a7b to 8f635c6 Compare March 9, 2026 02:27
@dahlia dahlia added this to the Fedify 2.1 milestone Mar 9, 2026
Register the unverified-activity hook from InboxListenerSetters
instead of Federatable so the API stays grouped with inbox
listener configuration and reads naturally in the chaining flow.

Update the builder, mock federation, tests, documentation, and
changelog text to reflect the new registration point without
changing the underlying inbox verification behavior.

fedify-dev#472

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 9, 2026 02:37
@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

@codex review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust mechanism for handling unverified inbound activities by adding the Federatable.onUnverifiedActivity() hook. This allows applications to define custom logic for activities that fail signature verification, which is particularly useful for handling Delete activities from actors whose keys are no longer accessible. The changes are well-supported by a more detailed signature verification API (verifyRequestDetailed) that provides structured failure reasons, and enhanced observability through new OpenTelemetry attributes. The implementation is clean, well-tested across multiple packages, and the documentation has been updated accordingly. Overall, this is an excellent enhancement to the library's flexibility and debugging capabilities.

Note: Security Review did not run due to the size of the PR.

@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new onUnverifiedActivity() handler for inspecting inbound activities that fail signature verification, allowing for custom response handling instead of the default 401 Unauthorized. The implementation also adds verifyRequestDetailed() to provide more granular information about signature verification failures, such as unsigned requests or key fetch errors. These details are also exposed through new OpenTelemetry attributes for improved tracing. The associated documentation and tests have been updated to cover these new features. The changes are logically sound and consistently applied throughout the codebase.

Note: Security Review did not run due to the size of the PR.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 192e8cbca2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 81.73759% with 103 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/fedify/src/sig/http.ts 72.32% 42 Missing and 2 partials ⚠️
packages/fedify/src/federation/handler.ts 68.68% 30 Missing and 1 partial ⚠️
packages/fedify/src/sig/key.ts 91.57% 15 Missing and 1 partial ⚠️
packages/fedify/src/otel/exporter.ts 62.50% 6 Missing ⚠️
packages/fedify/src/federation/keycache.ts 96.38% 3 Missing ⚠️
packages/testing/src/mock.ts 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
packages/fedify/src/federation/builder.ts 50.27% <100.00%> (+0.38%) ⬆️
packages/fedify/src/federation/middleware.ts 95.52% <100.00%> (+<0.01%) ⬆️
packages/fedify/src/sig/mod.ts 100.00% <100.00%> (ø)
packages/vocab-runtime/src/docloader.ts 86.95% <100.00%> (+0.06%) ⬆️
packages/vocab-runtime/src/request.ts 75.47% <100.00%> (+0.96%) ⬆️
packages/fedify/src/federation/keycache.ts 94.16% <96.38%> (+3.46%) ⬆️
packages/testing/src/mock.ts 64.80% <0.00%> (-0.34%) ⬇️
packages/fedify/src/otel/exporter.ts 84.75% <62.50%> (-1.07%) ⬇️
packages/fedify/src/sig/key.ts 86.46% <91.57%> (+2.86%) ⬆️
packages/fedify/src/federation/handler.ts 80.31% <68.68%> (-1.53%) ⬇️
... and 1 more
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses #472 by enabling Fedify applications to inspect inbound activities whose HTTP signatures could not be verified. Instead of always returning 401 Unauthorized, applications can now register a callback to handle unverified activities (e.g., accepting Delete activities from actors whose keys return 410 Gone).

Changes:

  • Added InboxListenerSetters.onUnverifiedActivity() with supporting types UnverifiedActivityHandler and UnverifiedActivityReason, and wired the callback through the federation builder, middleware, and inbox handler so unverified activities can be intercepted before the default 401 response.
  • Introduced verifyRequestDetailed() and fetchKeyDetailed() with structured failure result types (VerifyRequestDetailedResult, VerifyRequestFailureReason, FetchKeyErrorResult, FetchKeyDetailedResult) to distinguish unsigned requests, invalid signatures, and key-fetch failures, and extended FetchError in @fedify/vocab-runtime with an optional response field.
  • Added OpenTelemetry attributes for HTTP signature failure reasons and key-fetch details, updated FedifySpanExporter and documentation accordingly.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/vocab-runtime/src/request.ts Added optional response field to FetchError
packages/vocab-runtime/src/docloader.ts Pass cloned response to FetchError on HTTP errors
packages/vocab-runtime/src/docloader.test.ts Tests for FetchError.response
packages/testing/src/mock.ts Added onUnverifiedActivity stub to mock federation
packages/fedify/src/sig/key.ts Added fetchKeyDetailed, FetchKeyDetailedResult, FetchKeyErrorResult, withFetchKeySpan helper
packages/fedify/src/sig/key.test.ts Tests for fetchKeyDetailed
packages/fedify/src/sig/http.ts Added verifyRequestDetailed, detailed result types, failure helpers, span recording
packages/fedify/src/sig/http.test.ts Tests for verifyRequestDetailed
packages/fedify/src/otel/exporter.ts Added failure reason fields to SignatureVerificationDetails
packages/fedify/src/otel/exporter.test.ts Tests for new exporter fields
packages/fedify/src/federation/middleware.ts Pass unverifiedActivityHandler to inbox handler
packages/fedify/src/federation/middleware.test.ts Integration tests for onUnverifiedActivity
packages/fedify/src/federation/handler.ts Use verifyRequestDetailed, invoke unverified activity handler
packages/fedify/src/federation/handler.test.ts Tests for handler with unverified activity details
packages/fedify/src/federation/federation.ts Added onUnverifiedActivity to InboxListenerSetters interface
packages/fedify/src/federation/callback.ts Added UnverifiedActivityReason and UnverifiedActivityHandler types
packages/fedify/src/federation/builder.ts Builder implementation for onUnverifiedActivity
packages/fedify/src/federation/builder.test.ts Tests for builder copying the handler
docs/manual/opentelemetry.md Documented new OTel attributes
docs/manual/inbox.md Documented onUnverifiedActivity with example
CHANGES.md Changelog entries

dahlia and others added 3 commits March 9, 2026 11:53
Expose the new detailed HTTP signature and key-fetch APIs from
@fedify/fedify/sig so the documented public surface is available
to supported consumers instead of only internal source-path
imports.

fedify-dev#611 (comment)
fedify-dev#611 (comment)
fedify-dev#611 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
Add regression tests for fetchKeyDetailed() so both fetchError
variants are exercised: HTTP failures that carry a Response and
non-HTTP failures that only expose the thrown Error.

fedify-dev#611 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
Refactor fetchKeyDetailed() and fetchKeyInternal() to share
the cache lookup, remote document fetch, and fetched-document
resolution paths so key-fetch behavior is kept in one place.

This keeps the detailed fetch-error reporting added in this PR
while reducing the risk that later bug fixes or behavior changes
would diverge between the detailed and legacy code paths.

fedify-dev#611 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 9, 2026 03:01
@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

@codex review

@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

/gemini review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 342e5d0521

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature for handling unverified inbound activities by adding the onUnverifiedActivity handler and providing detailed signature verification results. The changes are well-implemented across the signature verification, request handling, and OpenTelemetry exporting layers. The related documentation and tests have been updated thoroughly to reflect these new capabilities.

Note: Security Review did not run due to the size of the PR.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.

Persist negative key-cache entries and their fetch failure metadata
through KvKeyCache so repeated verification attempts can keep
reporting keyFetchError details instead of degrading to
invalidSignature after the first miss.

Also add regression coverage for cached-null persistence,
fetch-error metadata round-tripping, and inbox retries that
should continue seeing the original 410 result.

fedify-dev#611 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 9, 2026 03:24
@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

@codex review

@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust mechanism for handling unverified inbound activities, a valuable addition for dealing with real-world federation scenarios like deleted actors. The changes are well-structured, introducing onUnverifiedActivity() for custom handling, verifyRequestDetailed() for granular failure reasons, and extending FetchError to include the original HTTP response. The implementation is consistent across the codebase, with corresponding updates to tests, documentation, and OpenTelemetry instrumentation. The refactoring in the signature verification and key fetching logic is clean and effectively isolates the new functionality. Overall, this is a high-quality contribution that enhances Fedify's error handling and observability.

Note: Security Review did not run due to the size of the PR.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 991f18e02a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.

dahlia and others added 2 commits March 9, 2026 13:11
Give KvKeyCache a short TTL for unavailable keys and persisted
fetch-failure metadata so temporary network errors or 5xx
responses do not poison signature verification indefinitely.

Also add regression coverage for expiring unavailable entries and
for round-tripping stored fetch-failure metadata.

fedify-dev#611 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
Catch exceptions thrown by onUnverifiedActivity(), forward them
to inboxErrorHandler, and fall back to the default 401 response
instead of letting unverified deliveries escape as uncaught 500s.

Add regression coverage to ensure hook failures are reported to
the inbox error handler and still produce the default unauthorized
response.

fedify-dev#611 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 9, 2026 04:13
@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

@codex review

@dahlia
Copy link
Member Author

dahlia commented Mar 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature for handling unverified inbound activities by adding the onUnverifiedActivity hook. This provides applications with more granular control over federation behavior, especially in real-world scenarios like handling deleted actors. The introduction of verifyRequestDetailed and the propagation of detailed failure reasons, including HTTP status codes from key fetches, significantly improve the observability and debugging capabilities of the library. The changes are well-structured, thoroughly tested, and clearly documented.

Note: Security Review did not run due to the size of the PR.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.

@dahlia dahlia merged commit f5543fc into fedify-dev:main Mar 10, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

activitypub/interop Interoperability issues component/federation Federation object related component/inbox Inbox related component/signatures OIP or HTTP/LD Signatures related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve handling of activities signed by non-resolvable actors

2 participants

X Tutup