Skip to content

Commit

Permalink
Merge pull request #38 from sip49/pixeebot/drip-2024-07-30-codeql-jav…
Browse files Browse the repository at this point in the history
…a/missing-jwt-signature-check

(CodeQL) Fixed finding: "Switch JWT calls to versions that enforce signature validity"
  • Loading branch information
sip49 authored Sep 25, 2024
2 parents cf1b850 + 782a708 commit 9f98d40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.owasp.webgoat.lessons.jwt;

import io.jsonwebtoken.Jws;
import static org.springframework.http.ResponseEntity.ok;

import io.jsonwebtoken.Claims;
Expand Down Expand Up @@ -110,7 +111,7 @@ public ResponseEntity<AttackResult> checkout(
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
try {
Jwt jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parse(token.replace("Bearer ", ""));
Jws<Claims> jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parseClaimsJws(token.replace("Bearer ", ""));
Claims claims = (Claims) jwt.getBody();
String user = (String) claims.get("user");
if ("Tom".equals(user)) {
Expand All @@ -136,8 +137,8 @@ public ResponseEntity newToken(
String user;
String refreshToken;
try {
Jwt<Header, Claims> jwt =
Jwts.parser().setSigningKey(JWT_PASSWORD).parse(token.replace("Bearer ", ""));
Jws<Claims> jwt =
Jwts.parser().setSigningKey(JWT_PASSWORD).parseClaimsJws(token.replace("Bearer ", ""));
user = (String) jwt.getBody().get("user");
refreshToken = (String) json.get("refresh_token");
} catch (ExpiredJwtException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.owasp.webgoat.lessons.jwt;

import io.jsonwebtoken.Jws;
import static java.util.Comparator.comparingLong;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -156,7 +157,7 @@ public MappingJacksonValue getVotes(
value.setSerializationView(Views.GuestView.class);
} else {
try {
Jwt jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parse(accessToken);
Jws<Claims> jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parseClaimsJws(accessToken);
Claims claims = (Claims) jwt.getBody();
String user = (String) claims.get("user");
if ("Guest".equals(user) || !validUsers.contains(user)) {
Expand All @@ -181,7 +182,7 @@ public ResponseEntity<?> vote(
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
} else {
try {
Jwt jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parse(accessToken);
Jws<Claims> jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parseClaimsJws(accessToken);
Claims claims = (Claims) jwt.getBody();
String user = (String) claims.get("user");
if (!validUsers.contains(user)) {
Expand All @@ -204,7 +205,7 @@ public AttackResult resetVotes(
return failed(this).feedback("jwt-invalid-token").build();
} else {
try {
Jwt jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parse(accessToken);
Jws<Claims> jwt = Jwts.parser().setSigningKey(JWT_PASSWORD).parseClaimsJws(accessToken);
Claims claims = (Claims) jwt.getBody();
boolean isAdmin = Boolean.valueOf(String.valueOf(claims.get("admin")));
if (!isAdmin) {
Expand Down

0 comments on commit 9f98d40

Please sign in to comment.