diff --git a/app/controllers/cors_controller.rb b/app/controllers/cors_controller.rb
index 943c5e3..ad30298 100644
--- a/app/controllers/cors_controller.rb
+++ b/app/controllers/cors_controller.rb
@@ -2,10 +2,19 @@ class CorsController < ApplicationController
skip_before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization
def preflight
- headers['Access-Control-Allow-Origin'] = Setting.plugin_redmine_cors["cors_domain"].to_s
- headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT'
- headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version, Content-Type, X-Redmine-API-Key'
- headers['Access-Control-Max-Age'] = '1728000'
+ allowed_origins = Setting.plugin_redmine_cors["cors_domain"].to_s.downcase.split(/[ ,]/).reject { |c| c.empty? }
+ if not request.headers["Origin"].nil?
+ if allowed_origins.include?("*") || allowed_origins.include?(request.headers["Origin"].to_s.downcase)
+ headers['Access-Control-Allow-Origin'] = request.headers["Origin"].to_s
+ headers['Access-Control-Allow-Methods'] = Setting.plugin_redmine_cors["cors_methods"]
+ headers['Access-Control-Allow-Headers'] = Setting.plugin_redmine_cors["cors_headers"]
+ headers['Access-Control-Max-Age'] = Setting.plugin_redmine_cors["cors_maxage"]
+ if (Setting.plugin_redmine_cors["cors_credentials"] == '1')
+ headers['Access-Control-Allow-Credentials'] = 'true'
+ end
+ end
+ end
+ headers['Vary'] = 'Origin'
render :text => '', :content_type => 'text/plain'
end
end
diff --git a/app/views/settings/_cors_settings.erb b/app/views/settings/_cors_settings.erb
index 0464d78..7b206de 100644
--- a/app/views/settings/_cors_settings.erb
+++ b/app/views/settings/_cors_settings.erb
@@ -5,3 +5,34 @@
<%= l(:description_cors_domain) %>
+ <%=content_tag(:label, l(:label_cors_headers) + ":") %>
+ <%=text_field_tag "settings[cors_headers]", @settings["cors_headers"], :size => 100 %>
+ (<%=l(:label_default)%>: 0)
+
+ <%= l(:description_cors_headers) %>
+
+ <%=content_tag(:label, l(:label_cors_methods) + ":") %>
+ <%=text_field_tag "settings[cors_methods]", @settings["cors_methods"], :size => 100 %>
+ (<%=l(:label_default)%>: 0)
+
+ <%= l(:description_cors_methods) %>
+
+ <%=content_tag(:label, l(:label_cors_maxage) + ":") %>
+ <%=text_field_tag "settings[cors_maxage]", @settings["cors_maxage"], :size => 100 %>
+ (<%=l(:label_default)%>: 0)
+
+ <%= l(:description_cors_maxage) %>
+
+ <%=content_tag(:label, l(:label_cors_credentials) + ":") %>
+ <%=check_box_tag "settings[cors_credentials]", '1', @settings["cors_credentials"] %>
+ (<%=l(:label_default)%>: 0)
+
+ <%= l(:description_cors_credentials) %>
+