CONVERTED_TYPES = %w(Image Video Article).freeze
def perform
- return if delete_arrived_first?(object_uri) || unsupported_object_type?
+ return if delete_arrived_first?(object_uri) || unsupported_object_type? || invalid_origin?(@object['id'])
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
def object_url
return if @object['url'].blank?
- url_to_href(@object['url'], 'text/html')
+
+ url_candidate = url_to_href(@object['url'], 'text/html')
+
+ if invalid_origin?(url_candidate)
+ nil
+ else
+ url_candidate
+ end
end
def content_language_map?
@skip_download ||= DomainBlock.find_by(domain: @account.domain)&.reject_media?
end
+ def invalid_origin?(url)
+ return true if unsupported_uri_scheme?(url)
+
+ needle = Addressable::URI.parse(url).host
+ haystack = Addressable::URI.parse(@account.uri).host
+
+ !haystack.casecmp(needle).zero?
+ end
+
def reply_to_local?
!replied_to_status.nil? && replied_to_status.account.local?
end
# Should be called with confirmed valid JSON
# and WebFinger-resolved username and domain
def call(username, domain, json)
- return if json['inbox'].blank?
+ return if json['inbox'].blank? || unsupported_uri_scheme?(json['id'])
@json = json
@uri = @json['id']
def url
return if @json['url'].blank?
- url_to_href(@json['url'], 'text/html')
+
+ url_candidate = url_to_href(@json['url'], 'text/html')
+
+ if unsupported_uri_scheme?(url_candidate) || mismatching_origin?(url_candidate)
+ nil
+ else
+ url_candidate
+ end
+ end
+
+ def mismatching_origin?(url)
+ needle = Addressable::URI.parse(url).host
+ haystack = Addressable::URI.parse(@uri).host
+
+ !haystack.casecmp(needle).zero?
end
def outbox_total_items
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
- id: 'foo',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
type: 'Create',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: object_json,
subject { described_class.new(json, sender) }
before do
+ sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
+
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
end
context 'standalone' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
}
context 'public' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: 'https://www.w3.org/ns/activitystreams#Public',
context 'unlisted' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
cc: 'https://www.w3.org/ns/activitystreams#Public',
context 'private' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: 'http://example.com/followers',
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: ActivityPub::TagManager.instance.uri_for(recipient),
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
tag: [
context 'with mentions missing href' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
tag: [
context 'with media attachments' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
attachment: [
context 'with media attachments missing url' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
attachment: [
context 'with hashtags' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
tag: [
context 'with hashtags missing name' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
tag: [
context 'with emojis' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum :tinking:',
tag: [
context 'with emojis missing name' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum :tinking:',
tag: [
context 'with emojis missing icon' do
let(:object_json) do
{
- id: 'bar',
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum :tinking:',
tag: [
describe '#call' do
before do
+ sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
+
stub_request(:head, 'https://example.com/watch?v=12345').to_return(status: 404, body: '')
subject.call(object[:id], prefetched_body: Oj.dump(object))
end
{
type: 'Link',
mimeType: 'application/x-bittorrent',
- href: 'https://example.com/12345.torrent',
+ href: "https://#{valid_domain}/12345.torrent",
},
{
type: 'Link',
mimeType: 'text/html',
- href: 'https://example.com/watch?v=12345',
+ href: "https://#{valid_domain}/watch?v=12345",
},
],
}
status = sender.statuses.first
expect(status).to_not be_nil
- expect(status.url).to eq 'https://example.com/watch?v=12345'
- expect(strip_tags(status.text)).to eq 'Nyan Cat 10 hours remix https://example.com/watch?v=12345'
+ expect(status.url).to eq "https://#{valid_domain}/watch?v=12345"
+ expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remix https://#{valid_domain}/watch?v=12345"
end
end
end