authlogic 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 599fa6150e2129f6366ed5cee0db158d6e7152a523174c1df72cd28b4877bf07
4
- data.tar.gz: 4bb06ac0d0d6d34ff7ced64861823c03920256df29961fd19ebd0ac820e04cd0
3
+ metadata.gz: c4ede36ceee21501805105c66349d58ba6c6d9d483d5fefc41b8d4cbd5189944
4
+ data.tar.gz: f323b446e8f8e2a722bb9d896249170596f64ebf8ff441b2740cb834c2b085b8
5
5
  SHA512:
6
- metadata.gz: 35e71d8dc041a482b80127e36a0bd60296df1b472db130b481c843cccaa2969c946f936ca9e9faf2603de62c4dae1f20967fa0aa929e24429b7204b331761204
7
- data.tar.gz: dcf067170c35323dd8159bef69e2053af0b9c4fee96d5886d0b00404dd63b8eafc44601799c6f1a4261f9680b231fd5c4fa05eb64121eea9cb20ad8433df256f
6
+ metadata.gz: 26cda51c7c8e2b5a8be9395ef13e3d39d9ee1c73429542d107bb229747b9a004800771a96b8f516e4f994c8926b1d0ef2fb1bf45e38102646451c48a3e4fb453
7
+ data.tar.gz: 971d54be27f18e12d8d7eafad90e50627098c689b34e047c0ddea4a96f82abf8c80e45766f49fdd82a9efb45fd3508ca312ee4b0cc0508d06a37887d45f9fcb0
@@ -961,6 +961,20 @@ module Authlogic
961
961
  end
962
962
  alias sign_cookie= sign_cookie
963
963
 
964
+ # Should the cookie be encrypted? If the controller adapter supports it, this is a
965
+ # measure to hide the contents of the cookie (e.g. persistence_token)
966
+ def encrypt_cookie(value = nil)
967
+ if value && !controller.cookies.respond_to?(:encrypted)
968
+ raise "Encrypted cookies not supported with #{controller.class}!"
969
+ end
970
+ if value && sign_cookie
971
+ raise "It is recommended to use encrypt_cookie instead of sign_cookie. " \
972
+ "You may not enable both options."
973
+ end
974
+ rw_config(:encrypt_cookie, value, false)
975
+ end
976
+ alias_method :encrypt_cookie=, :encrypt_cookie
977
+
964
978
  # Works exactly like cookie_key, but for sessions. See cookie_key for more info.
965
979
  #
966
980
  # * <tt>Default:</tt> cookie_key
@@ -1480,6 +1494,23 @@ module Authlogic
1480
1494
  sign_cookie == true || sign_cookie == "true" || sign_cookie == "1"
1481
1495
  end
1482
1496
 
1497
+ # If the cookie should be encrypted
1498
+ def encrypt_cookie
1499
+ return @encrypt_cookie if defined?(@encrypt_cookie)
1500
+ @encrypt_cookie = self.class.encrypt_cookie
1501
+ end
1502
+
1503
+ # Accepts a boolean as to whether the cookie should be encrypted. If true
1504
+ # the cookie will be saved in an encrypted state.
1505
+ def encrypt_cookie=(value)
1506
+ @encrypt_cookie = value
1507
+ end
1508
+
1509
+ # See encrypt_cookie
1510
+ def encrypt_cookie?
1511
+ encrypt_cookie == true || encrypt_cookie == "true" || encrypt_cookie == "1"
1512
+ end
1513
+
1483
1514
  # The scope of the current object
1484
1515
  def scope
1485
1516
  @scope ||= {}
@@ -1623,7 +1654,9 @@ module Authlogic
1623
1654
  end
1624
1655
 
1625
1656
  def cookie_jar
1626
- if self.class.sign_cookie
1657
+ if self.class.encrypt_cookie
1658
+ controller.cookies.encrypted
1659
+ elsif self.class.sign_cookie
1627
1660
  controller.cookies.signed
1628
1661
  else
1629
1662
  controller.cookies
@@ -1705,13 +1738,8 @@ module Authlogic
1705
1738
 
1706
1739
  # @api private
1707
1740
  def generate_cookie_for_saving
1708
- creds = ::Authlogic::CookieCredentials.new(
1709
- record.persistence_token,
1710
- record.send(record.class.primary_key),
1711
- remember_me? ? remember_me_until : nil
1712
- )
1713
1741
  {
1714
- value: creds.to_s,
1742
+ value: generate_cookie_value.to_s,
1715
1743
  expires: remember_me_until,
1716
1744
  secure: secure,
1717
1745
  httponly: httponly,
@@ -1720,6 +1748,14 @@ module Authlogic
1720
1748
  }
1721
1749
  end
1722
1750
 
1751
+ def generate_cookie_value
1752
+ ::Authlogic::CookieCredentials.new(
1753
+ record.persistence_token,
1754
+ record.send(record.class.primary_key),
1755
+ remember_me? ? remember_me_until : nil
1756
+ )
1757
+ end
1758
+
1723
1759
  # Returns a Proc to be executed by
1724
1760
  # `ActionController::HttpAuthentication::Basic` when credentials are
1725
1761
  # present in the HTTP request.
@@ -1935,11 +1971,7 @@ module Authlogic
1935
1971
  end
1936
1972
 
1937
1973
  def save_cookie
1938
- if sign_cookie?
1939
- controller.cookies.signed[cookie_key] = generate_cookie_for_saving
1940
- else
1941
- controller.cookies[cookie_key] = generate_cookie_for_saving
1942
- end
1974
+ cookie_jar[cookie_key] = generate_cookie_for_saving
1943
1975
  end
1944
1976
 
1945
1977
  # @api private
@@ -23,6 +23,10 @@ module Authlogic
23
23
  def signed
24
24
  @signed ||= MockSignedCookieJar.new(self)
25
25
  end
26
+
27
+ def encrypted
28
+ @encrypted ||= MockEncryptedCookieJar.new(self)
29
+ end
26
30
  end
27
31
 
28
32
  # A mock of `ActionDispatch::Cookies::SignedKeyRotatingCookieJar`
@@ -35,6 +39,7 @@ module Authlogic
35
39
 
36
40
  def initialize(parent_jar)
37
41
  @parent_jar = parent_jar
42
+ parent_jar.each { |k, v| self[k] = v }
38
43
  end
39
44
 
40
45
  def [](val)
@@ -51,5 +56,35 @@ module Authlogic
51
56
  @parent_jar[key] = options
52
57
  end
53
58
  end
59
+
60
+ class MockEncryptedCookieJar < MockCookieJar
61
+ attr_reader :parent_jar # helper for testing
62
+
63
+ def initialize(parent_jar)
64
+ @parent_jar = parent_jar
65
+ parent_jar.each { |k, v| self[k] = v }
66
+ end
67
+
68
+ def [](val)
69
+ encrypted_message = @parent_jar[val]
70
+ if encrypted_message
71
+ self.class.decrypt(encrypted_message)
72
+ end
73
+ end
74
+
75
+ def []=(key, options)
76
+ options[:value] = self.class.encrypt(options[:value])
77
+ @parent_jar[key] = options
78
+ end
79
+
80
+ # simple caesar cipher for testing
81
+ def self.encrypt(str)
82
+ str.unpack("U*").map(&:succ).pack("U*")
83
+ end
84
+
85
+ def self.decrypt(str)
86
+ str.unpack("U*").map(&:pred).pack("U*")
87
+ end
88
+ end
54
89
  end
55
90
  end
@@ -17,6 +17,6 @@ module Authlogic
17
17
  #
18
18
  # @api public
19
19
  def self.gem_version
20
- ::Gem::Version.new("5.1.0")
20
+ ::Gem::Version.new("5.2.0")
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-03-24 00:00:00.000000000 Z
13
+ date: 2020-05-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel