-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed improper handling of response cookies. Update core.js.
- Loading branch information
Showing
11 changed files
with
408 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
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
54 changes: 54 additions & 0 deletions
54
...n/src/main/java/synfron/reshaper/burp/core/messages/entities/http/HttpRequestHeaders.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,63 @@ | ||
package synfron.reshaper.burp.core.messages.entities.http; | ||
|
||
import synfron.reshaper.burp.core.rules.GetItemPlacement; | ||
import synfron.reshaper.burp.core.rules.SetItemPlacement; | ||
import synfron.reshaper.burp.core.utils.CaseInsensitiveString; | ||
import synfron.reshaper.burp.core.utils.IValue; | ||
|
||
import java.util.List; | ||
|
||
public class HttpRequestHeaders extends HttpHeaders { | ||
public HttpRequestHeaders(List<String> headerLines) { | ||
super(headerLines, "Cookie"); | ||
} | ||
|
||
@Override | ||
public String getCookie(String cookieName, GetItemPlacement itemPlacement) { | ||
HttpRequestCookies cookies = (HttpRequestCookies)getHeaders().get(new CaseInsensitiveString(cookieHeaderName), GetItemPlacement.Last); | ||
if (cookies != null) { | ||
return cookies.getCookie(cookieName, itemPlacement); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setCookie(String cookieName, String value, SetItemPlacement itemPlacement) { | ||
HttpRequestCookies cookies = (HttpRequestCookies)getHeaders().get(new CaseInsensitiveString(cookieHeaderName), GetItemPlacement.Last); | ||
if (cookies != null) { | ||
cookies.setCookie(cookieName, value, itemPlacement); | ||
if (value == null) { | ||
if (cookies.getCount() == 0) { | ||
getHeaders().removeLast(new CaseInsensitiveString(cookieHeaderName)); | ||
} | ||
} | ||
} else if (value != null) { | ||
getHeaders().add(new CaseInsensitiveString(cookieName), createCookie(cookieName, value)); | ||
} | ||
changed = true; | ||
} | ||
|
||
@Override | ||
public IValue<String> createCookie(String value) { | ||
return new HttpRequestCookies(value); | ||
} | ||
|
||
@Override | ||
public List<String> getCookiesNames() { | ||
HttpRequestCookies cookies = (HttpRequestCookies)getHeaders().get(new CaseInsensitiveString(cookieHeaderName), GetItemPlacement.Last); | ||
if (cookies != null) { | ||
return cookies.getCookiesNames(); | ||
} | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public boolean containsCookie(String cookieName) { | ||
HttpRequestCookies cookies = (HttpRequestCookies)getHeaders().get(new CaseInsensitiveString(cookieHeaderName), GetItemPlacement.Last); | ||
return cookies != null && cookies.contains(cookieName); | ||
} | ||
|
||
private IValue<String> createCookie(String name, String value) { | ||
return new HttpRequestCookies(String.format("%s=%s", name, value)); | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
...n/src/main/java/synfron/reshaper/burp/core/messages/entities/http/HttpResponseCookie.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package synfron.reshaper.burp.core.messages.entities.http; | ||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.commons.lang3.StringUtils; | ||
import synfron.reshaper.burp.core.rules.DeleteItemPlacement; | ||
import synfron.reshaper.burp.core.rules.GetItemPlacement; | ||
import synfron.reshaper.burp.core.rules.IItemPlacement; | ||
import synfron.reshaper.burp.core.rules.SetItemPlacement; | ||
import synfron.reshaper.burp.core.utils.CaseInsensitiveString; | ||
import synfron.reshaper.burp.core.utils.CollectionUtils; | ||
import synfron.reshaper.burp.core.utils.IValue; | ||
import synfron.reshaper.burp.core.utils.ListMap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
|
||
public class HttpResponseCookie extends HttpEntity implements IValue<String> { | ||
|
||
private String name; | ||
private String value; | ||
private String config; | ||
private final String headerValue; | ||
@Getter | ||
private boolean changed; | ||
|
||
public HttpResponseCookie(String headerValue) { | ||
this.headerValue = headerValue; | ||
} | ||
|
||
public HttpResponseCookie(String name, String value) { | ||
headerValue = String.format("%s=%s", name, value); | ||
} | ||
|
||
private void initialize() { | ||
if (name == null) { | ||
int configSeparatorIndex = headerValue.indexOf(";"); | ||
String setter = headerValue.substring(0, configSeparatorIndex >= 0 ? configSeparatorIndex : headerValue.length()); | ||
String[] setterParts = setter.split("=", 2); | ||
name = setterParts[0]; | ||
value = CollectionUtils.elementAtOrDefault(setterParts, 1, ""); | ||
config = configSeparatorIndex >= 0 ? headerValue.substring(configSeparatorIndex) : ""; | ||
} | ||
} | ||
|
||
public void setCookieValue(String value) { | ||
initialize(); | ||
this.value = value; | ||
changed = true; | ||
} | ||
|
||
public String getCookieValue() { | ||
initialize(); | ||
return value; | ||
} | ||
|
||
public String getValue() { | ||
if (!isChanged()) { | ||
return headerValue; | ||
} | ||
return String.format("%s=%s%s", name, value, config); | ||
} | ||
|
||
public String getName() { | ||
initialize(); | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getValue(); | ||
} | ||
} |
Oops, something went wrong.