Skip to content

Commit 4e1733d

Browse files
Gate SLO endpoints behind slo_enabled option
1 parent f82193a commit 4e1733d

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Note that when [integrating with Devise](#devise-integration), the URL path will
103103
instance will be passed to this callable if it has an arity of 1. If the value is a string,
104104
the string will be returned, when the `RelayState` is called. Optional.
105105

106+
* `:slo_enabled` - Enables or disables Single Logout (SLO). Set to `false` to disable SLO. Defaults to `true`. Optional.
107+
106108
* `:idp_sso_service_url_runtime_params` - A dynamic mapping of request params that exist
107109
during the request phase of OmniAuth that should to be sent to the IdP after a specific
108110
mapping. So for example, a param `original_request_param` with value `original_param_value`,
@@ -112,7 +114,7 @@ Note that when [integrating with Devise](#devise-integration), the URL path will
112114
* `:idp_cert` - The identity provider's certificate in PEM format. Takes precedence
113115
over the fingerprint option below. This option or `:idp_cert_multi` or `:idp_cert_fingerprint` must
114116
be present.
115-
117+
116118
* `:idp_cert_multi` - Multiple identity provider certificates in PEM format. Takes precedence
117119
over the fingerprint option below. This option `:idp_cert` or `:idp_cert_fingerprint` must
118120
be present.
@@ -192,7 +194,9 @@ Single Logout can be Service Provider initiated or Identity Provider initiated.
192194
For SP initiated logout, the `idp_slo_service_url` option must be set to the logout url on the IdP,
193195
and users directed to `user_saml_omniauth_authorize_path + '/spslo'` after logging out locally. For
194196
IdP initiated logout, logout requests from the IdP should go to `/auth/saml/slo` (this can be
195-
advertised in metadata by setting the `single_logout_service_url` config option).
197+
advertised in metadata by setting the `single_logout_service_url` config option). If you wish to
198+
disable Single Logout entirely (both SP and IdP initiated), set `:slo_enabled => false`; the `/auth/saml/slo`
199+
and `/auth/saml/spslo` endpoints will then respond with HTTP 501 Not Implemented.
196200

197201
When using Devise as an authentication solution, the SP initiated flow can be integrated
198202
in the `SessionsController#destroy` action.

lib/omniauth/strategies/saml.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def self.inherited(subclass)
2828
last_name: ["last_name", "lastname", "lastName"]
2929
}
3030
option :slo_default_relay_state
31+
option :slo_enabled, true
3132
option :uid_attribute
3233
option :idp_slo_session_destroy, proc { |_env, session| session.clear }
3334

@@ -259,6 +260,14 @@ def other_phase_for_spslo
259260
end
260261
end
261262

263+
def slo_enabled?
264+
!!options[:slo_enabled]
265+
end
266+
267+
def slo_disabled_response
268+
Rack::Response.new("Not Implemented", 501, { "Content-Type" => "text/html" }).finish
269+
end
270+
262271
def add_request_attributes_to(settings)
263272
settings.attribute_consuming_service.service_name options.attribute_service_name
264273
settings.sp_entity_id = options.sp_entity_id

spec/omniauth/strategies/saml_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ def post_xml(xml = :example_response, opts = {})
268268
expect(last_request.env['omniauth.error'].message).to eq("SAML response missing 'missing_attribute' attribute")
269269
end
270270
end
271-
272271
end
273272

274273
describe 'POST /auth/saml/slo' do
@@ -277,6 +276,10 @@ def post_xml(xml = :example_response, opts = {})
277276
end
278277

279278
context "when response is a logout response" do
279+
before do
280+
saml_options[:slo_enabled] = true
281+
end
282+
280283
before :each do
281284
post "/auth/saml/slo", {
282285
SAMLResponse: load_xml(:example_logout_response),
@@ -336,6 +339,10 @@ def post_xml(xml = :example_response, opts = {})
336339
end
337340

338341
describe 'POST /auth/saml/spslo' do
342+
before do
343+
saml_options[:slo_enabled] = true
344+
end
345+
339346
def test_default_relay_state(static_default_relay_state = nil, &block_default_relay_state)
340347
saml_options["slo_default_relay_state"] = static_default_relay_state || block_default_relay_state
341348
post "/auth/saml/spslo"

0 commit comments

Comments
 (0)