Skip to content

Commit b26e118

Browse files
committed
Prevent none algorithm from being valid with a key configured
1 parent 297e09b commit b26e118

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

JSONWebToken.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'JSONWebToken'
3-
spec.version = '1.0.0'
3+
spec.version = '1.0.1'
44
spec.summary = 'Swift library for JSON Web Tokens (JWT).'
55
spec.homepage = 'https://github.com/kylef/JSONWebToken.swift'
66
spec.license = { :type => 'BSD', :file => 'LICENSE' }

JWT/JWT.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public enum Algorithm : Printable {
1313

1414
static func algorithm(name:String, key:String?) -> Algorithm? {
1515
if name == "none" {
16+
if let key = key {
17+
return nil // We don't allow nil when we configured a key
18+
}
1619
return Algorithm.None
1720
} else if let key = key {
1821
if name == "HS256" {

JWTTests/JWTTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class JWTDecodeTests : XCTestCase {
143143
XCTAssertEqual(payload as NSDictionary, ["test": "ing"])
144144
}
145145
}
146+
147+
func testNoneFailsWithSecretAlgorithm() {
148+
let jwt = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJ0ZXN0IjoiaW5nIn0."
149+
assertFailure(decode(jwt, key:"secret"))
150+
}
146151
}
147152

148153
// MARK: Helpers

0 commit comments

Comments
 (0)