Skip to content

Commit

Permalink
fix: align XSRF token duration with the session cookie one
Browse files Browse the repository at this point in the history
fixes AM-875

fixes gravitee-io/issues#9282

(cherry picked from commit 7db91e8)
  • Loading branch information
leleueri committed Oct 9, 2023
1 parent 79eed17 commit 2e9cbbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import static io.vertx.ext.web.handler.SessionHandler.DEFAULT_SESSION_TIMEOUT;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
Expand All @@ -34,9 +36,12 @@ public class CSRFHandlerFactory implements FactoryBean<CSRFHandler> {
@Autowired
private Vertx vertx;

@Value("${http.cookie.session.timeout:" + DEFAULT_SESSION_TIMEOUT + "}")
private long timeout;

@Override
public CSRFHandler getObject() {
return CSRFHandler.newInstance(new CSRFHandlerImpl(vertx, csrfSecret));
return CSRFHandler.newInstance(new CSRFHandlerImpl(vertx, csrfSecret, timeout));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ public class CSRFHandlerImpl implements CSRFHandler {
private String cookieName = DEFAULT_COOKIE_NAME;
private String cookiePath = DEFAULT_COOKIE_PATH;
private String headerName = DEFAULT_HEADER_NAME;
private long timeout = SessionHandler.DEFAULT_SESSION_TIMEOUT;
private long timeout;
private String origin;
private boolean httpOnly;
private boolean cookieSecure;

public CSRFHandlerImpl(Vertx vertx, final String secret) {
public CSRFHandlerImpl(Vertx vertx, final String secret, final long timeout) {
this.RAND = VertxContextPRNG.current(vertx);
this.timeout = timeout;
try {
mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(), "HmacSHA256"));
Expand Down

0 comments on commit 2e9cbbe

Please sign in to comment.