-
Notifications
You must be signed in to change notification settings - Fork 265
KNOX-3232: Handle pac4j cookies with "null" value #1132
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
Conversation
Test Results7 tests 7 ✅ 1s ⏱️ Results for commit c7fa377. |
hanicz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as I understand the culprit behind the "null" value is sb.append('=').append(value); in SetCookieHeader, right?
Wouldn't it be better to fix that by appending an empty value?
Also the SetCookieHeader class was introduced because with java 8 the sameSite attribute was missing from org.pac4j.core.context.Cookie. Is switching back an option?
We could switch back as now setSameSitePolicy() is available on org.pac4j.core.context.Cookie. It would still generate name=null; if the cookie value is null. Cookie cookie;
if (value == null) {
cookie = new Cookie(PAC4J_SESSION_PREFIX + key, null);
}
...
if(sessionStoreConfigs != null && sessionStoreConfigs.containsKey(PAC4J_COOKIE_SAMESITE)) {
cookie.setSameSitePolicy(sessionStoreConfigs.get(PAC4J_COOKIE_SAMESITE));
}
context.addResponseCookie(cookie); public static String createCookieHeader(Cookie cookie) {
var builder = new StringBuilder();
builder.append(String.format("%s=%s;", cookie.getName(), cookie.getValue()));there are some extra logic in createCookieHeader and we need to make sure that it's consistent with what we have now: var sameSitePolicy = cookie.getSameSitePolicy() == null ? "lax" : cookie.getSameSitePolicy().toLowerCase();
switch (sameSitePolicy) {
case "strict" -> builder.append(" SameSite=Strict;");
case "none" -> builder.append(" SameSite=None;");
default -> builder.append(" SameSite=Lax;");
}
if (cookie.isSecure() || "none".equals(sameSitePolicy)) {
builder.append(" Secure;");
}For now, I would keep it as it is, and create another issue to switch back to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
The mentioned changes will be done in https://issues.apache.org/jira/browse/KNOX-3233
KNOX-3232 - Handle pac4j cookies with "null" value
What changes were proposed in this pull request?
Just handle the case when our set-cookie header is setting explicit null values and KnoxSessionStore receives the cookie with "null" value.
How was this patch tested?
Manual test with CAS global logout url as described in the JIRA.
Added a unit test in KnoxSessionStoreTests.