ignore unused params

This commit is contained in:
Damian Bednarczyk
2023-11-29 15:03:30 -06:00
parent dc558b38fa
commit 382d5f3744
4 changed files with 21 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package responsemodifers
import (
"fmt"
http "github.com/bogdanfinn/fhttp"
//"net/http"
//http "github.com/Danny-Dasilva/fhttp"
@@ -11,7 +12,7 @@ import (
// DeleteIncomingCookies prevents ALL cookies from being sent from the proxy server
// back down to the client.
func DeleteIncomingCookies(whitelist ...string) proxychain.ResponseModification {
func DeleteIncomingCookies(_ ...string) proxychain.ResponseModification {
return func(px *proxychain.ProxyChain) error {
px.Response.Header.Del("Set-Cookie")
return nil
@@ -37,6 +38,7 @@ func DeleteIncomingCookiesExcept(whitelist ...string) proxychain.ResponseModific
filteredCookies := []string{}
for _, cookieStr := range px.Response.Header["Set-Cookie"] {
cookie := parseCookie(cookieStr)
if _, found := whitelistMap[cookie.Name]; found {
filteredCookies = append(filteredCookies, cookieStr)
}

View File

@@ -111,6 +111,7 @@ func (r *HTMLTokenURLRewriter) ShouldModify(token *html.Token) bool {
func (r *HTMLTokenURLRewriter) ModifyToken(token *html.Token) (string, string) {
for i := range token.Attr {
attr := &token.Attr[i]
switch {
// don't touch tag/attributes that don't contain URIs
case !rewriteAttrs[token.Data][attr.Key]:
@@ -192,9 +193,11 @@ func handleRootRelativePath(attr *html.Attribute, baseURL *url.URL) {
// Document-relative URLs: These are relative to the current document's path and don't start with a "/".
func handleDocumentRelativePath(attr *html.Attribute, baseURL *url.URL) {
log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val)
if strings.HasPrefix(attr.Val, "#") {
return
}
relativePath := path.Join(strings.Trim(baseURL.RawPath, "/"), strings.Trim(attr.Val, "/"))
attr.Val = fmt.Sprintf(
"%s://%s/%s",
@@ -204,13 +207,15 @@ func handleDocumentRelativePath(attr *html.Attribute, baseURL *url.URL) {
)
attr.Val = escape(attr.Val)
attr.Val = fmt.Sprintf("/%s", attr.Val)
log.Printf("doc rel url rewritten-> '%s'='%s'", attr.Key, attr.Val)
}
// full URIs beginning with https?://proxiedsite.com
func handleAbsolutePath(attr *html.Attribute, baseURL *url.URL) {
func handleAbsolutePath(attr *html.Attribute, _ *url.URL) {
// check if valid URL
log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val)
u, err := url.Parse(attr.Val)
if err != nil {
return
@@ -218,6 +223,7 @@ func handleAbsolutePath(attr *html.Attribute, baseURL *url.URL) {
if !(u.Scheme == "http" || u.Scheme == "https") {
return
}
attr.Val = fmt.Sprintf("/%s", escape(strings.TrimPrefix(attr.Val, "/")))
//attr.Val = fmt.Sprintf("/%s", escape(attr.Val))

View File

@@ -34,7 +34,7 @@ func (r *ScriptInjectorRewriter) ShouldModify(token *html.Token) bool {
//go:embed after_dom_idle_script_injector.js
var afterDomIdleScriptInjector string
func (r *ScriptInjectorRewriter) ModifyToken(token *html.Token) (string, string) {
func (r *ScriptInjectorRewriter) ModifyToken(_ *html.Token) (string, string) {
switch {
case r.execTime == BeforeDOMContentLoaded:
return "", fmt.Sprintf("\n<script>\n%s\n</script>\n", r.script)
@@ -58,6 +58,7 @@ func (r *ScriptInjectorRewriter) applyParams(params map[string]string) {
for key := range params {
keys = append(keys, key)
}
sort.Slice(keys, func(i, j int) bool {
return len(keys[i]) > len(keys[j])
})