Skip to content

Conversation

@allouis
Copy link
Contributor

@allouis allouis commented Jul 23, 2025

Summary

There is a bug when handling redirects in doubleKnock when the Location header includes a path, rather than a full URL

Changes

  • Redirect URL is now constructed using the original URL as a base

Benefits

This allows full URLs to continue to work, whilst paths will be resolved relative to the original

Checklist

  • Did you add a changelog entry to the CHANGES.md?
  • Did you write some relevant docs about this change (if it's a new feature)?
  • Did you write a regression test to reproduce the bug (if it's a bug fix)?
  • Did you write some tests for this change (if it's a new feature)?
  • Did you run deno task test-all on your machine?

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.

Summary of Changes

Hello @allouis, 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 addresses a critical bug in the doubleKnock function that prevented it from correctly following HTTP redirects when the Location header specified a relative path. The changes ensure that all redirect URLs, whether absolute or relative, are properly resolved against the original request's context, significantly improving the reliability of activity sending. A new regression test has also been included to validate the fix.

Highlights

  • Bug Fix: Path-Based Redirects: I've identified and fixed a bug in the doubleKnock function where it failed to correctly handle HTTP redirects when the Location header provided a relative path (e.g., /some/path) instead of a full URL. The previous implementation would not correctly resolve these relative paths, leading to failed requests.
  • Improved URL Resolution: The core change involves modifying the createRedirectRequest function to use the URL constructor with both the location header value and the original request's URL as a base. This ensures that relative redirect paths are properly resolved into absolute URLs, allowing doubleKnock to follow redirects correctly regardless of the Location header format.
  • Regression Test Added: A new regression test has been added to fedify/sig/http.test.ts that specifically reproduces the bug with path-based redirects and verifies that the fix correctly allows doubleKnock to complete the request successfully. This ensures the bug does not re-emerge in the future.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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.

@github-actions github-actions bot added component/federation Federation object related priority/medium Medium priority issues status/in progress In progress type/bug Something isn't working type/test Testing related labels Jul 23, 2025
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 correctly fixes a bug in handling redirects where the Location header contains a relative path. The change in fedify/sig/http.ts to use the original request URL as a base for resolving the redirect location is the right approach. The addition of a regression test in fedify/sig/http.test.ts is excellent for preventing future regressions. I have one suggestion to make the new test even more robust.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 23, 2025

The docs for this pull request have been published:

https://2241f6c8.fedify.pages.dev

Copy link
Member

@dahlia dahlia left a comment

Choose a reason for hiding this comment

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

Good catch. Thanks for your contribution! Could you make this pull request target at the 1.6-maintenance branch instead of the main branch?

@allouis allouis changed the base branch from main to 1.6-maintenance July 24, 2025 13:07
@allouis allouis force-pushed the handle-redirects branch from 729f2bb to 3fcf258 Compare July 24, 2025 13:08
@github-actions github-actions bot added the priority/high High priority issues label Jul 24, 2025
allouis added 2 commits July 24, 2025 23:01
When the Location header contains just the path to redirect to Fedify
will error with something like `TypeError Failed to parse URL from ...`

This ensures that the path will be resolved relative to the original URL
@dahlia dahlia force-pushed the handle-redirects branch from 3fcf258 to 0b7ecec Compare July 24, 2025 14:01
@github-actions
Copy link
Contributor

The latest push to this pull request has been published to JSR and npm as a pre-release:

@dahlia dahlia merged commit 658fb77 into fedify-dev:1.6-maintenance Jul 24, 2025
16 checks passed
@dahlia
Copy link
Member

dahlia commented Jul 24, 2025

This fix is shipped with v1.6.7 and v1.7.6 releases.

@allouis allouis deleted the handle-redirects branch July 24, 2025 14:40
allouis added a commit to TryGhost/ActivityPub that referenced this pull request Jul 28, 2025
ref fedify-dev/fedify#335
ref fedify-dev/fedify#324

This bump to fedify includes two fixes the the doubleKnock
implementation. One which is an attempt to remedy the 'unusable' errors
when cloning the request objects, and the other which handles relative
paths in the Location header when recieving a redirect.

Both of these errors cause significant noise in our production
environment and cleaning them up should allow us to spot real errors a
lot easier in future.
allouis added a commit to TryGhost/ActivityPub that referenced this pull request Jul 28, 2025
ref fedify-dev/fedify#335
ref fedify-dev/fedify#324

This bump to fedify includes two fixes the the doubleKnock
implementation. One which is an attempt to remedy the 'unusable' errors
when cloning the request objects, and the other which handles relative
paths in the Location header when recieving a redirect.

Both of these errors cause significant noise in our production
environment and cleaning them up should allow us to spot real errors a
lot easier in future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/federation Federation object related priority/high High priority issues priority/medium Medium priority issues status/in progress In progress type/bug Something isn't working type/test Testing related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants