Skip to content
Open
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
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -199,6 +199,26 @@ protected String getSessionId(@NotNull HttpServletRequest request) {
return httpSession.getId();
}

/**
* Rotates the session ID after successful authentication to prevent session fixation attacks.
*/
public void rotateSessionId(@NotNull HttpServletRequest request) {
HttpSession oldSession = request.getSession(false);
if (oldSession == null) {
log.debug("No HTTP session present, skipping session ID rotation");
return;
}
String oldSessionId = oldSession.getId();
String newSessionId = request.changeSessionId();
synchronized (sessionMap) {
BaseWebSession webSession = sessionMap.remove(oldSessionId);
if (webSession != null) {
sessionMap.put(newSessionId, webSession);
}
}
log.debug("Session ID rotated after authentication ('" + oldSessionId + "' -> '" + newSessionId + "')");
}

/**
* Returns not expired session from cache, or restore it.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,8 @@
public interface DBWServiceAuth extends DBWService {

@WebAction(authRequired = false)
WebAuthStatus authLogin(

Check warning on line 38 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/DBWServiceAuth.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'WebAuthStatus' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/DBWServiceAuth.java:38:5: warning: Reference type 'WebAuthStatus' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
@NotNull HttpServletRequest httpRequest,
@NotNull WebSession webSession,
@NotNull String providerId,
@Nullable String providerConfigurationId,
Expand All @@ -55,7 +56,8 @@
) throws DBWebException;

@WebAction(authRequired = false)
WebAsyncAuthTaskResult federatedAuthTaskResult(

Check warning on line 59 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/DBWServiceAuth.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'WebAsyncAuthTaskResult' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/DBWServiceAuth.java:59:5: warning: Reference type 'WebAsyncAuthTaskResult' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
@NotNull HttpServletRequest httpRequest,
@NotNull WebSession webSession,
@NotNull String taskId
) throws DBWebException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@
//to get auth result
@Nullable
private List<WebAuthInfo> authResult;
private boolean sessionRotated;

public WebAsyncAuthJob(@NotNull String name, @NotNull String authId, boolean linkWithUser) {
super(name);
Expand All @@ -46,8 +47,7 @@
protected IStatus run(@NotNull DBRProgressMonitor monitor) {
return null;
}

@NotNull

Check warning on line 50 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/WebAsyncAuthJob.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'METHOD_DEF' should be separated from previous line. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/WebAsyncAuthJob.java:50:5: warning: 'METHOD_DEF' should be separated from previous line. (com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck)
public String getAuthId() {
return authId;
}
Expand All @@ -65,4 +65,12 @@
this.authResult = authResult;
}

public boolean isSessionRotated() {
return sessionRotated;
}

public void setSessionRotated(boolean sessionRotated) {
this.sessionRotated = sessionRotated;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,9 +34,10 @@
}

@Override
public void bindWiring(DBWBindingContext model) {

Check warning on line 37 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/WebServiceBindingAuth.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'DBWBindingContext' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/WebServiceBindingAuth.java:37:28: warning: Reference type 'DBWBindingContext' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
model.getQueryType()
.dataFetcher("authLogin", env -> getService(env).authLogin(
GraphQLEndpoint.getServletRequestOrThrow(env),
getWebSession(env, false),
getArgumentVal(env, "provider"),
getArgument(env, "configuration"),
Expand All @@ -45,6 +46,7 @@
CommonUtils.toBoolean(getArgument(env, "forceSessionsLogout"))
))
.dataFetcher("federatedAuthTaskResult", env -> getService(env).federatedAuthTaskResult(
GraphQLEndpoint.getServletRequestOrThrow(env),
getWebSession(env, false),
getArgumentVal(env, "taskId")
))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +66,8 @@
private static final long DEFAULT_TIMEOUT_MILLISECONDS = 5 * 60 * 1000;

@Override
public WebAuthStatus authLogin(

Check warning on line 69 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/impl/WebServiceAuthImpl.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'WebAuthStatus' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/impl/WebServiceAuthImpl.java:69:12: warning: Reference type 'WebAuthStatus' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
@NotNull HttpServletRequest httpRequest,
@NotNull WebSession webSession,
@NotNull String providerId,
@Nullable String providerConfigurationId,
Expand All @@ -85,7 +86,9 @@
} else {
//run it sync
var authProcessor = new WebSessionAuthProcessor(webSession, smAuthInfo, linkWithActiveUser);
return new WebAuthStatus(smAuthInfo.getAuthStatus(), authProcessor.authenticateSession());
List<WebAuthInfo> authInfos = authProcessor.authenticateSession();
CBApplication.getInstance().getSessionManager().rotateSessionId(httpRequest);
return new WebAuthStatus(smAuthInfo.getAuthStatus(), authInfos);
}
} catch (SMTooManySessionsException e) {
throw new DBWebException("User authentication failed", e.getErrorType(), e);
Expand Down Expand Up @@ -139,7 +142,11 @@
}

@Override
public WebAsyncAuthTaskResult federatedAuthTaskResult(@NotNull WebSession webSession, @NotNull String taskId) throws DBWebException {
public WebAsyncAuthTaskResult federatedAuthTaskResult(

Check warning on line 145 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/impl/WebServiceAuthImpl.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'WebAsyncAuthTaskResult' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/impl/WebServiceAuthImpl.java:145:12: warning: Reference type 'WebAsyncAuthTaskResult' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
@NotNull HttpServletRequest httpRequest,
@NotNull WebSession webSession,
@NotNull String taskId
) throws DBWebException {
WebAsyncTaskInfo taskInfo = webSession.asyncTaskStatus(taskId, true);
if (taskInfo == null) {
throw new DBWebException("Task '" + taskId + "' not found");
Expand All @@ -154,6 +161,9 @@
List<WebAuthInfo> userTokens = job.getAuthResult();
if (CommonUtils.isEmpty(userTokens)) {
userTokens = List.of();
} else if (!job.isSessionRotated()) {
CBApplication.getInstance().getSessionManager().rotateSessionId(httpRequest);
job.setSessionRotated(true);
}
return new WebAsyncAuthTaskResult(userTokens);
}
Expand Down Expand Up @@ -261,6 +271,7 @@
}
}
}
CBApplication.getInstance().getSessionManager().rotateSessionId(httpRequest);
return new WebLogoutInfo(logoutUrls);
} catch (DBException e) {
throw new DBWebException("User logout failed", e);
Expand Down
Loading