diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 254bbaf0b..289150a87 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -157,7 +157,7 @@ class StatusMessage < Post def contains_oembed_url_in_text? require 'uri' urls = URI.extract(self.raw_message, ['http', 'https']) - self.oembed_url = urls.find{|url| ENDPOINT_HOSTS_STRING.match(URI.parse(url).host)} + self.oembed_url = urls.find{ |url| !TRUSTED_OEMBED_PROVIDERS.find(url).nil? } end protected diff --git a/config/initializers/oembed.rb b/config/initializers/oembed.rb index 9fe992eea..8f615eed0 100644 --- a/config/initializers/oembed.rb +++ b/config/initializers/oembed.rb @@ -1,16 +1,20 @@ require 'oembed' require 'uri' -OEmbed::Providers.register_all +OEmbedCubbies = OEmbed::Provider.new("http://cubbi.es/oembed") + +OEmbed::Providers.register( + OEmbed::Providers::Youtube, + OEmbed::Providers::Vimeo, + OEmbed::Providers::Flickr, + OEmbed::Providers::SoundCloud, + OEmbedCubbies +) OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery) + # # SECURITY NOTICE! CROSS-SITE SCRIPTING! # these endpoints may inject html code into our page # note that 'trusted_endpoint_url' is the only information # in OEmbed that we can trust. anything else may be spoofed! -SECURE_ENDPOINTS = [::OEmbed::Providers::Youtube.endpoint, - ::OEmbed::Providers::Flickr.endpoint, - 'http://soundcloud.com/oembed', - 'http://cubbi.es/oembed' - ] -ENDPOINT_HOSTS_STRING = SECURE_ENDPOINTS.map{|e| URI.parse(e.split('{')[0]).host}.to_s +TRUSTED_OEMBED_PROVIDERS = OEmbed::Providers