Skip to content

Commit 1fe8406

Browse files
committed
🔒 SASL PLAIN: Raise ArgumentError for conflicts
1 parent 3446056 commit 1fe8406

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/net/imap/sasl/plain_authenticator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Net::IMAP::SASL::PlainAuthenticator
1616

1717
# Authentication identity: the identity that matches the #password.
1818
#
19+
# RFC-2831[https://tools.ietf.org/html/rfc2831] uses the term +username+.
20+
# "Authentication identity" is the generic term used by
21+
# RFC-4422[https://tools.ietf.org/html/rfc4422].
1922
# RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
2023
# this to +authcid+.
2124
attr_reader :username
@@ -53,6 +56,10 @@ class Net::IMAP::SASL::PlainAuthenticator
5356
# See attribute documentation for more details.
5457
def initialize(user = nil, pass = nil,
5558
username: nil, password: nil, authzid: nil, **)
59+
[username, user].compact.count == 1 or
60+
raise ArgumentError, "conflicting values for username"
61+
[password, pass].compact.count == 1 or
62+
raise ArgumentError, "conflicting values for password"
5663
username ||= user or raise ArgumentError, "missing username"
5764
password ||= pass or raise ArgumentError, "missing password"
5865
raise ArgumentError, "username contains NULL" if username.include?(NULL)

0 commit comments

Comments
 (0)