Skip to content

A platform for community discussion. Free, open, simple.

FIX: Include routes in an API scope's allowed URLs even if they have no format constraints

OsamaSayegh5eaf4b8553be
diff --git a/app/models/api_key_scope.rb b/app/models/api_key_scope.rb
index a0b86bf590b..b829ae479a6 100644
--- a/app/models/api_key_scope.rb
+++ b/app/models/api_key_scope.rb
@@ -120,7 +120,11 @@ class ApiKeyScope < ActiveRecord::Base
defaults = route.defaults
action = "#{defaults[:controller].to_s}##{defaults[:action]}"
path = route.path.spec.to_s.gsub(/\(\.:format\)/, '')
- api_supported_path = path.end_with?('.rss') || route.path.requirements[:format]&.match?('json')
+ api_supported_path = (
+ path.end_with?('.rss') ||
+ !route.path.requirements[:format] ||
+ route.path.requirements[:format].match?('json')
+ )
excluded_paths = %w[/new-topic /new-message /exception]
if actions.include?(action) && api_supported_path && !excluded_paths.include?(path)