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

Issue 51904: Strict-Transport-Security header when HTTPS is required #6168

Merged
merged 3 commits into from
Dec 22, 2024
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion api/src/org/labkey/api/security/AuthFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
}

// No startup failure, so check for SSL redirection
if (!req.getScheme().equalsIgnoreCase("https") && AppProps.getInstance().isSSLRequired())
boolean sslRequired = AppProps.getInstance().isSSLRequired();
if (!req.getScheme().equalsIgnoreCase("https") && sslRequired)
{
// We can't redirect posts (we'll lose the post body), so return an error code
if ("post".equalsIgnoreCase(req.getMethod()))
Expand Down Expand Up @@ -164,6 +165,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
return;
}

if (sslRequired)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a devMode check. I believe the reason we don't already have this is because it is incredibly sticky. If you do this on a dev machine and test SSL, you won't be able to use http: until next year or until you figure out how to make your browser forget this setting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ask me how I know...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea. Update pushed.

{
resp.setHeader("Strict-Transport-Security", "max-age=31536000");
}

// allow CSRFUtil early access to req/resp if it wants to write cookies
CSRFUtil.getExpectedToken(req, resp);

Expand Down
Loading