Skip to content

Commit 6e3ba7a

Browse files
committed
Fix header parsing for Authorization scheme.
1 parent b566ad2 commit 6e3ba7a

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

build.savant

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ logbackVersion = "1.5.13"
2929
slf4jVersion = "2.0.13"
3030
testngVersion = "7.8.0"
3131

32-
project(group: "org.primeframework", name: "prime-mvc", version: "5.5.0", licenses: ["ApacheV2_0"]) {
32+
project(group: "org.primeframework", name: "prime-mvc", version: "5.5.1", licenses: ["ApacheV2_0"]) {
3333
workflow {
3434
fetch {
3535
// Dependency resolution order:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.primeframework</groupId>
77
<artifactId>prime-mvc</artifactId>
8-
<version>5.5.0</version>
8+
<version>5.5.1</version>
99
<packaging>jar</packaging>
1010

1111
<name>FusionAuth App</name>

src/main/java/org/primeframework/mvc/security/DefaultJWTRequestAdapter.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2023, Inversoft Inc., All Rights Reserved
2+
* Copyright (c) 2016-2025, Inversoft Inc., All Rights Reserved
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,10 @@
3838
* @author Daniel DeGroff
3939
*/
4040
public class DefaultJWTRequestAdapter implements JWTRequestAdapter {
41+
private static final String BearerScheme = "bearer ";
42+
43+
private static final String JWTScheme = "jwt ";
44+
4145
protected final HTTPRequest request;
4246

4347
protected final HTTPResponse response;
@@ -52,11 +56,12 @@ public DefaultJWTRequestAdapter(HTTPRequest request, HTTPResponse response) {
5256
public String getEncodedJWT() {
5357
String authorization = request.getHeader("Authorization");
5458
if (authorization != null) {
55-
// Support Bearer and JWT scheme
56-
if (authorization.startsWith("Bearer ")) {
57-
return authorization.substring("Bearer ".length());
58-
} else if (authorization.startsWith("JWT ")) {
59-
return authorization.substring("JWT ".length());
59+
// Support Bearer and JWT scheme. The JWT scheme is only for backwards compatability with usage.
60+
// - Match on scheme case-insensitive, but return the un-modified value.
61+
if (authorization.toLowerCase().startsWith(BearerScheme)) {
62+
return authorization.substring(BearerScheme.length());
63+
} else if (authorization.toLowerCase().startsWith(JWTScheme)) {
64+
return authorization.substring(JWTScheme.length());
6065
}
6166
}
6267

src/test/java/org/primeframework/mvc/GlobalTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,25 @@ public void get_jwtAuthorized() throws Exception {
783783
.assertHeaderContains("Cache-Control", "no-cache")
784784
.assertStatusCode(200));
785785

786+
// Test with JWT scheme, mixed case
787+
test.simulate(() -> simulator.test("/jwt-authorized")
788+
.withHeader("Authorization", "jWt eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkifQ.qHdut1UR4-2FSAvh7U3YdeRR5r5boVqjIGQ16Ztp894")
789+
.get()
790+
.assertHeaderContains("Cache-Control", "no-cache")
791+
.assertStatusCode(200));
792+
786793
// Test with Bearer scheme
787794
test.simulate(() -> simulator.test("/jwt-authorized")
788795
.withHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkifQ.qHdut1UR4-2FSAvh7U3YdeRR5r5boVqjIGQ16Ztp894")
789796
.get()
790797
.assertStatusCode(200));
791798

799+
// Test with Bearer scheme, mixed case
800+
test.simulate(() -> simulator.test("/jwt-authorized")
801+
.withHeader("Authorization", "bEaReR eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkifQ.qHdut1UR4-2FSAvh7U3YdeRR5r5boVqjIGQ16Ztp894")
802+
.get()
803+
.assertStatusCode(200));
804+
792805
// Missing JWT w/ Bearer scheme
793806
test.simulate(() -> simulator.test("/jwt-authorized")
794807
.withHeader("Authorization", "Bearer ")

0 commit comments

Comments
 (0)