Instantly share code, notes, and snippets.
Created
March 9, 2023 15:00
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save mlbiam/19e69e5209c767387b95e85ab6e79721 to your computer and use it in GitHub Desktop.
cookie monster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application azTimeoutMillis="30000" isApp="true" name="CookieMonster"> | |
<results/> | |
<urls> | |
<url authChain="Anonymous" overrideHost="true" overrideReferer="true" regex="false"> | |
<host>#[OU_HOST]</host> | |
<filterChain> | |
<filter class="XX.XXXXX.XXXX.DeleteCookies"> | |
<param name="domain" value="#[OU_HOST]"/> | |
<param name="override" value="false" /> | |
<param name="cookies"> | |
<![CDATA[ | |
{ | |
"name": "XXXXopen", | |
"path": "/", | |
"httpOnly": true, | |
"secure": true, | |
"useDomain": true, | |
"domain": "#[OU_HOST]" | |
} | |
]]> | |
</param> | |
<param name="cookies"> | |
<![CDATA[ | |
{ | |
"name": "autoIdmAppName", | |
"path": "/", | |
"httpOnly": true, | |
"secure": true, | |
"useDomain": true, | |
"domain": "#[OU_HOST]" | |
} | |
]]> | |
</param> | |
<param name="cookies"> | |
<![CDATA[ | |
{ | |
"name": "autoIdmSessionCookieName", | |
"path": "/", | |
"httpOnly": true, | |
"secure": true, | |
"useDomain": true, | |
"domain": "#[OU_HOST]" | |
} | |
]]> | |
</param> | |
<param name="cookies"> | |
<![CDATA[ | |
{ | |
"name": "XXXXsession", | |
"path": "/", | |
"httpOnly": true, | |
"secure": true, | |
"useDomain": true, | |
"domain": "#[OU_HOST]" | |
} | |
]]> | |
</param> | |
</filter> | |
<filter class="com.tremolosecurity.prelude.filters.StopProcessing"/> | |
</filterChain> | |
<uri>/clear-cookies</uri> | |
<results> | |
<auSuccess/> | |
<auFail>Default Invalid Credentials</auFail> | |
<azSuccess>send-to-logout</azSuccess> | |
<azFail>Default Login Failure</azFail> | |
</results> | |
<azRules> | |
<rule constraint="o=Tremolo" scope="dn"/> | |
</azRules> | |
</url> | |
</urls> | |
<cookieConfig> | |
<sessionCookieName>XXXXsession</sessionCookieName> | |
<domain>#[OU_HOST]</domain> | |
<scope>-1</scope> | |
<logoutURI>/logout</logoutURI> | |
<keyAlias>session-tremolosession</keyAlias> | |
<secure>true</secure> | |
<timeout>900</timeout> | |
<httpOnly>true</httpOnly> | |
<sameSite>None</sameSite> | |
</cookieConfig> | |
</application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package XXXXXX; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.servlet.http.Cookie; | |
import com.google.gson.Gson; | |
import com.tremolosecurity.proxy.cookies.UnisonCookie; | |
import com.tremolosecurity.proxy.filter.HttpFilter; | |
import com.tremolosecurity.proxy.filter.HttpFilterChain; | |
import com.tremolosecurity.proxy.filter.HttpFilterConfig; | |
import com.tremolosecurity.proxy.filter.HttpFilterRequest; | |
import com.tremolosecurity.proxy.filter.HttpFilterResponse; | |
public class DeleteCookies implements HttpFilter { | |
List<CookieToRemove> cookiesToRemove; | |
boolean override; | |
String domain; | |
@Override | |
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception { | |
for (CookieToRemove cookieToRemove : this.cookiesToRemove) { | |
UnisonCookie cookie = new UnisonCookie(cookieToRemove.getName(),"DELETE"); | |
cookie.setDomain(this.domain); | |
cookie.setPath(cookieToRemove.getPath()); | |
cookie.setMaxAge(0); | |
if (cookieToRemove.isHttpOnly()) { | |
cookie.setHttpOnly(true); | |
} | |
if (cookieToRemove.isSecure()) { | |
cookie.setSecure(true); | |
} | |
cookie.setOverrideValues(this.override); | |
if (cookieToRemove.isUseDomain()) { | |
cookie.setDomain(cookieToRemove.getDomain()); | |
} | |
response.addCookie(cookie); | |
} | |
chain.nextFilter(request, response, chain); | |
} | |
@Override | |
public void filterResponseBinary(HttpFilterRequest arg0, HttpFilterResponse arg1, HttpFilterChain arg2, byte[] arg3, | |
int arg4) throws Exception { | |
} | |
@Override | |
public void filterResponseText(HttpFilterRequest arg0, HttpFilterResponse arg1, HttpFilterChain arg2, | |
StringBuffer arg3) throws Exception { | |
} | |
@Override | |
public void initFilter(HttpFilterConfig cfg) throws Exception { | |
cookiesToRemove = new ArrayList<CookieToRemove>(); | |
Gson gson = new Gson(); | |
for (String cookieConfig : cfg.getAttribute("cookies").getValues()) { | |
CookieToRemove cookie = gson.fromJson(cookieConfig, CookieToRemove.class); | |
this.cookiesToRemove.add(cookie); | |
} | |
this.domain = cfg.getAttribute("domain").getValues().get(0); | |
this.override = cfg.getAttribute("override").getValues().get(0).equalsIgnoreCase("true"); | |
} | |
} | |
class CookieToRemove { | |
String name; | |
String path; | |
boolean secure; | |
boolean httpOnly; | |
boolean useDomain; | |
String domain; | |
public CookieToRemove() { | |
} | |
/** | |
* @return the name | |
*/ | |
public String getName() { | |
return name; | |
} | |
/** | |
* @return the path | |
*/ | |
public String getPath() { | |
return path; | |
}/** | |
* @return the httpOnly | |
*/ | |
public boolean isHttpOnly() { | |
return httpOnly; | |
}/** | |
* @return the secure | |
*/ | |
public boolean isSecure() { | |
return secure; | |
}/** | |
* @param httpOnly the httpOnly to set | |
*/ | |
public void setHttpOnly(boolean httpOnly) { | |
this.httpOnly = httpOnly; | |
}/** | |
* @param name the name to set | |
*/ | |
public void setName(String name) { | |
this.name = name; | |
}/** | |
* @param path the path to set | |
*/ | |
public void setPath(String path) { | |
this.path = path; | |
}/** | |
* @param secure the secure to set | |
*/ | |
public void setSecure(boolean secure) { | |
this.secure = secure; | |
} | |
/** | |
* @return the domain | |
*/ | |
public String getDomain() { | |
return domain; | |
} | |
/** | |
* @return the useDomain | |
*/ | |
public boolean isUseDomain() { | |
return useDomain; | |
} | |
/** | |
* @param useDomain the useDomain to set | |
*/ | |
public void setUseDomain(boolean useDomain) { | |
this.useDomain = useDomain; | |
} | |
/** | |
* @param domain the domain to set | |
*/ | |
public void setDomain(String domain) { | |
this.domain = domain; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment