Redirect if collection AP ID is requested as HTML (#39361)

This commit is contained in:
David Roetzel 2026-06-10 17:54:50 +02:00 committed by GitHub
parent 1bbe3872f2
commit 008f377a37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -10,6 +10,7 @@ class CollectionsController < ApplicationController
before_action :require_account_signature!, only: :show, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_collection
before_action :redirect_to_canonical_url
skip_around_action :set_locale, if: -> { request.format == :json }
skip_before_action :require_functional!, only: :show, unless: :limited_federation_mode?
@ -45,6 +46,10 @@ class CollectionsController < ApplicationController
not_found
end
def redirect_to_canonical_url
redirect_to collection_path(@collection) if request.format.html? && request.path.starts_with?('/ap/')
end
def expiration_duration
recently_updated = @collection.updated_at > 15.minutes.ago
recently_updated ? 30.seconds : 5.minutes

View File

@ -29,6 +29,14 @@ RSpec.describe 'Collections' do
let(:collection) { Fabricate(:collection) }
let(:account) { collection.account }
context 'when requested as HTML' do
it 'redirects to canonical URL' do
get ap_account_collection_path(account.id, collection)
expect(response).to redirect_to(collection_path(collection))
end
end
context 'when signed out' do
context 'when account is permanently suspended' do
before do