Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes session cookie secure, httponly and set same site attribute #209

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Changes from 2 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 @@ -20,8 +20,11 @@
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.session.SessionHandler;

import javax.servlet.SessionCookieConfig;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -113,5 +116,14 @@ public void run(org.finos.legend.server.shared.staticserver.StaticServerConfigur
sessionHandler.setSessionCookie(staticServerConfiguration.getSessionCookie());
}
environment.servlets().setSessionHandler(sessionHandler);
makeSessionCookieSecure(environment.getApplicationContext().getServletContext());
}

private void makeSessionCookieSecure( ContextHandler.Context servletContext)
{
SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
Copy link
Contributor

@rafaelbey rafaelbey Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this ever be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen "JSESSIONID" getting always created with Dropwizard and Jetty so ideally SessionCookieConfig should not be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, added null check to avoid potential NPE.

sessionCookieConfig.setSecure(true);
sessionCookieConfig.setHttpOnly(true);
servletContext.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "STRICT");
}
}