gds-sso 23.1.0 → 23.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a95e61408af0e4dcc151b31d6ec2cba9bd0099b3ed13e8d6c11fabed4a597528
4
- data.tar.gz: 18a6a4441629042f3c0eb026419a6af2294870e7a378b073b3335e9ad31bef07
3
+ metadata.gz: e519d11d71dc81ff7f70180bab5237b3954fa4f2edcac6814e0043252cade007
4
+ data.tar.gz: b33e66525cc804a544aee4b50bedc9a8ead77aadf11d6f4ce7873428afd7b53f
5
5
  SHA512:
6
- metadata.gz: a78f8c4696ac1da20f32f6ee080efea0d46ff43461d6d41c1bce21a6172c0080d444778439d1ecf97cc3823f6ded0c9466bf7999de315f4ac9d220fda50425ad
7
- data.tar.gz: 39657e8cff0191f9e03d1cc949810031ab5aca512bc5cfd1a00899fca7d84ccf09782d5987d712de2ab5b623e57d26b8ab40897197008d979460c387ed81f126
6
+ metadata.gz: fec43e7bd64928d01744b37460461ccd3baa9dca87e0d1d4f224beb7e2883154dda3075ffa7bd96bc8e122c743f92311af8360226390dce5dbec2a2f93c65645
7
+ data.tar.gz: 3a8381e94c1601c3faac34129378515d91ca77548e29060e9f35ee586bb1559f8d317878952d8124f0f7ec1d489bdbc61f1978c746d3b5abb19dad4e59e9c538
@@ -13,11 +13,9 @@ module GDS
13
13
 
14
14
  def call(env)
15
15
  status, headers, body = @app.call(env)
16
-
17
16
  session = env["rack.session"]
18
- return [status, headers, body] unless session.respond_to?(:to_hash)
19
17
 
20
- if gds_sso_session_bytesize(session) > MAX_SESSION_DATA_SIZE
18
+ if session_in_use?(session) && session_exceeds_limit?(session)
21
19
  Rails.logger.warn("[gds-sso] Rejecting request: data added to the session by gds-sso exceeds #{MAX_SESSION_DATA_SIZE} bytes")
22
20
  purge_gds_sso_session_data!(session)
23
21
  return bad_request
@@ -28,6 +26,16 @@ module GDS
28
26
 
29
27
  private
30
28
 
29
+ # Only inspect sessions the app has already loaded. Forcing a load
30
+ # would otherwise emit a Set-Cookie on responses that never used it.
31
+ def session_in_use?(session)
32
+ session.respond_to?(:loaded?) && session.loaded?
33
+ end
34
+
35
+ def session_exceeds_limit?(session)
36
+ gds_sso_session_bytesize(session) > MAX_SESSION_DATA_SIZE
37
+ end
38
+
31
39
  def gds_sso_session_bytesize(session)
32
40
  session.to_hash.sum do |key, value|
33
41
  managed_key?(key) ? key.bytesize + serialized_bytesize(value) : 0
@@ -1,5 +1,5 @@
1
1
  module GDS
2
2
  module SSO
3
- VERSION = "23.1.0".freeze
3
+ VERSION = "23.1.1".freeze
4
4
  end
5
5
  end
@@ -1,6 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe "GDS-SSO session data limitation", type: :request do
4
+ context "when the application does not use the session" do
5
+ it "does not read the session, so no session cookie is emitted in the response" do
6
+ # Obtain a valid, under-limit session cookie
7
+ get "/restricted"
8
+ expect(response).to redirect_to("/auth/gds")
9
+
10
+ session_cookie = response.headers["Set-Cookie"]
11
+ expect(session_cookie).to be_present
12
+
13
+ # Access an endpoint that never touches the session
14
+ get "/not-restricted", headers: { "Cookie" => session_cookie.split(";").first }
15
+ expect(response).to have_http_status(:success)
16
+ expect(response.headers["Set-Cookie"]).to be_nil
17
+ end
18
+ end
4
19
  context "when a request would overflow the session cookie" do
5
20
  it "responds with 400 when the query string is oversized" do
6
21
  get "/auth/gds?payload=#{'A' * 6000}"
@@ -0,0 +1,30 @@
1
+ RSpec.describe GDS::SSO::LimitSessionData do
2
+ subject(:middleware) { described_class.new(app) }
3
+ let(:app) { ->(_env) { [200, { "content-type" => "text/plain" }, %w[ok]] } }
4
+
5
+ context "when the session isn't loaded" do
6
+ let(:session) { double("Unloaded Session", loaded?: false, to_hash: {}) }
7
+
8
+ it "passes through without reading an unloaded session" do
9
+ status, _headers, body = middleware.call("rack.session" => session)
10
+
11
+ expect(status).to eq(200)
12
+ expect(body).to eq(%w[ok])
13
+ expect(session).not_to have_received(:to_hash)
14
+ end
15
+ end
16
+
17
+ context "when the session is loaded" do
18
+ let(:session) { double("Loaded Session", loaded?: true, to_hash:, delete:) }
19
+ let(:to_hash) { { "omniauth.params" => { "payload" => "A" * 3000 } } }
20
+ let(:delete) { ->(key) { to_hash.delete(key) } }
21
+
22
+ it "will inspect a loaded session" do
23
+ status, = middleware.call("rack.session" => session)
24
+
25
+ expect(status).to eq(400)
26
+ expect(session).to have_received(:to_hash).twice
27
+ expect(session).to have_received(:delete).with("omniauth.params")
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-sso
3
3
  version: !ruby/object:Gem::Version
4
- version: 23.1.0
4
+ version: 23.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -290,6 +290,7 @@ files:
290
290
  - spec/unit/controller_methods_spec.rb
291
291
  - spec/unit/failure_app_spec.rb
292
292
  - spec/unit/gds_sso_spec.rb
293
+ - spec/unit/limit_session_data_spec.rb
293
294
  - spec/unit/mock_bearer_token_spec.rb
294
295
  - spec/unit/railtie_spec.rb
295
296
  - spec/unit/session_serialisation_spec.rb
@@ -312,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
313
  - !ruby/object:Gem::Version
313
314
  version: '0'
314
315
  requirements: []
315
- rubygems_version: 4.0.23
316
+ rubygems_version: 4.0.24
316
317
  specification_version: 4
317
318
  summary: Client for GDS' OAuth 2-based SSO
318
319
  test_files:
@@ -341,6 +342,7 @@ test_files:
341
342
  - spec/unit/controller_methods_spec.rb
342
343
  - spec/unit/failure_app_spec.rb
343
344
  - spec/unit/gds_sso_spec.rb
345
+ - spec/unit/limit_session_data_spec.rb
344
346
  - spec/unit/mock_bearer_token_spec.rb
345
347
  - spec/unit/railtie_spec.rb
346
348
  - spec/unit/session_serialisation_spec.rb