Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ protected String makeTokenSignature(long tokenExpiryTime, String username) {
UserSeedProperty userSeedProperty = user.getProperty(UserSeedProperty.class);
if (userSeedProperty == null) {
// if you want to filter out the user seed property, you should consider using the DISABLE_USER_SEED instead
return "no-prop";
userSeed = "no-prop";
} else {
userSeed = userSeedProperty.getSeed();
}
userSeed = userSeedProperty.getSeed();
}
String token = String.join(":", username, Long.toString(tokenExpiryTime), userSeed, getKey());
return MAC.mac(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,29 @@ synchronized void verifyInvocations(int count) {
}
}

@Test
void rememberMeToken_forgedWithNoProp_shouldNotAuthenticate() throws Exception {
j.jenkins.setDisableRememberMe(false);

HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false, false, null);
TokenBasedRememberMeServices2 tokenService = (TokenBasedRememberMeServices2) realm.getSecurityComponents().rememberMe2;
j.jenkins.setSecurityRealm(realm);

String username = "alice";
realm.createAccount(username, username);

// Craft a forged remember-me cookie with "no-prop" as the signature
JenkinsRule.WebClient wc = j.createWebClient();
long expiryTime = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1);
String forgedTokenValue = username + ":" + expiryTime + ":" + "no-prop";
String forgedTokenBase64 = Base64.getEncoder().encodeToString(forgedTokenValue.getBytes(StandardCharsets.UTF_8));
Cookie forgedCookie = new Cookie(j.getURL().getHost(), tokenService.getCookieName(), forgedTokenBase64);
wc.getCookieManager().addCookie(forgedCookie);

// The forged cookie should NOT authenticate the user
assertUserNotConnected(wc, username);
}

private Cookie createRememberMeCookie(TokenBasedRememberMeServices2 tokenService, long deltaDuration, hudson.model.User user) throws Exception {
long tokenValiditySeconds = tokenService.getTokenValiditySeconds();
long expiryTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(tokenValiditySeconds);
Expand Down