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

@@ -5,6 +5,9 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"net/url"
"strings"
//"time" //"time"
//"net/http" //"net/http"
@@ -12,10 +15,8 @@ import (
//http "github.com/Danny-Dasilva/fhttp" //http "github.com/Danny-Dasilva/fhttp"
http "github.com/bogdanfinn/fhttp" http "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client" tls_client "github.com/bogdanfinn/tls-client"
//"github.com/bogdanfinn/tls-client/profiles"
"net/url" //"github.com/bogdanfinn/tls-client/profiles"
"strings"
"ladder/pkg/ruleset" "ladder/pkg/ruleset"
@@ -122,7 +123,7 @@ type HTTPClient interface {
SetCookies(u *url.URL, cookies []*http.Cookie) SetCookies(u *url.URL, cookies []*http.Cookie)
SetCookieJar(jar http.CookieJar) SetCookieJar(jar http.CookieJar)
GetCookieJar() http.CookieJar GetCookieJar() http.CookieJar
SetProxy(proxyUrl string) error SetProxy(proxyURL string) error
GetProxy() string GetProxy() string
SetFollowRedirect(followRedirect bool) SetFollowRedirect(followRedirect bool)
GetFollowRedirect() bool GetFollowRedirect() bool
@@ -184,7 +185,7 @@ func (chain *ProxyChain) AddRuleset(rs *ruleset.RuleSet) *ProxyChain {
return chain return chain
} }
func (chain *ProxyChain) _initialize_request() (*http.Request, error) { func (chain *ProxyChain) _initializeRequest() (*http.Request, error) {
if chain.Context == nil { if chain.Context == nil {
chain.abortErr = chain.abort(errors.New("no context set")) chain.abortErr = chain.abort(errors.New("no context set"))
return nil, chain.abortErr return nil, chain.abortErr
@@ -264,9 +265,11 @@ func preventRecursiveProxyRequest(urlQuery *url.URL, baseProxyURL string) *url.U
// is a relative path, it reconstructs the full URL using the referer header. // is a relative path, it reconstructs the full URL using the referer header.
func (chain *ProxyChain) extractURL() (*url.URL, error) { func (chain *ProxyChain) extractURL() (*url.URL, error) {
reqURL := chain.Context.Params("*") reqURL := chain.Context.Params("*")
fmt.Println("XXXXXXXXXXXXXXXX") fmt.Println("XXXXXXXXXXXXXXXX")
fmt.Println(reqURL) fmt.Println(reqURL)
fmt.Println(chain._apiPrefix) fmt.Println(chain._apiPrefix)
reqURL = strings.TrimPrefix(reqURL, chain._apiPrefix) reqURL = strings.TrimPrefix(reqURL, chain._apiPrefix)
// sometimes client requests doubleroot '//' // sometimes client requests doubleroot '//'
@@ -318,7 +321,7 @@ func (chain *ProxyChain) SetFiberCtx(ctx *fiber.Ctx) *ProxyChain {
chain.Context = ctx chain.Context = ctx
// initialize the request and prepare it for modification // initialize the request and prepare it for modification
req, err := chain._initialize_request() req, err := chain._initializeRequest()
if err != nil { if err != nil {
chain.abortErr = chain.abort(err) chain.abortErr = chain.abort(err)
} }

View File

@@ -2,6 +2,7 @@ package responsemodifers
import ( import (
"fmt" "fmt"
http "github.com/bogdanfinn/fhttp" http "github.com/bogdanfinn/fhttp"
//"net/http" //"net/http"
//http "github.com/Danny-Dasilva/fhttp" //http "github.com/Danny-Dasilva/fhttp"
@@ -11,7 +12,7 @@ import (
// DeleteIncomingCookies prevents ALL cookies from being sent from the proxy server // DeleteIncomingCookies prevents ALL cookies from being sent from the proxy server
// back down to the client. // back down to the client.
func DeleteIncomingCookies(whitelist ...string) proxychain.ResponseModification { func DeleteIncomingCookies(_ ...string) proxychain.ResponseModification {
return func(px *proxychain.ProxyChain) error { return func(px *proxychain.ProxyChain) error {
px.Response.Header.Del("Set-Cookie") px.Response.Header.Del("Set-Cookie")
return nil return nil
@@ -37,6 +38,7 @@ func DeleteIncomingCookiesExcept(whitelist ...string) proxychain.ResponseModific
filteredCookies := []string{} filteredCookies := []string{}
for _, cookieStr := range px.Response.Header["Set-Cookie"] { for _, cookieStr := range px.Response.Header["Set-Cookie"] {
cookie := parseCookie(cookieStr) cookie := parseCookie(cookieStr)
if _, found := whitelistMap[cookie.Name]; found { if _, found := whitelistMap[cookie.Name]; found {
filteredCookies = append(filteredCookies, cookieStr) 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) { func (r *HTMLTokenURLRewriter) ModifyToken(token *html.Token) (string, string) {
for i := range token.Attr { for i := range token.Attr {
attr := &token.Attr[i] attr := &token.Attr[i]
switch { switch {
// don't touch tag/attributes that don't contain URIs // don't touch tag/attributes that don't contain URIs
case !rewriteAttrs[token.Data][attr.Key]: 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 "/". // 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) { func handleDocumentRelativePath(attr *html.Attribute, baseURL *url.URL) {
log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val) log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val)
if strings.HasPrefix(attr.Val, "#") { if strings.HasPrefix(attr.Val, "#") {
return return
} }
relativePath := path.Join(strings.Trim(baseURL.RawPath, "/"), strings.Trim(attr.Val, "/")) relativePath := path.Join(strings.Trim(baseURL.RawPath, "/"), strings.Trim(attr.Val, "/"))
attr.Val = fmt.Sprintf( attr.Val = fmt.Sprintf(
"%s://%s/%s", "%s://%s/%s",
@@ -204,13 +207,15 @@ func handleDocumentRelativePath(attr *html.Attribute, baseURL *url.URL) {
) )
attr.Val = escape(attr.Val) attr.Val = escape(attr.Val)
attr.Val = fmt.Sprintf("/%s", attr.Val) attr.Val = fmt.Sprintf("/%s", attr.Val)
log.Printf("doc rel url rewritten-> '%s'='%s'", attr.Key, attr.Val) log.Printf("doc rel url rewritten-> '%s'='%s'", attr.Key, attr.Val)
} }
// full URIs beginning with https?://proxiedsite.com // 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 // check if valid URL
log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val) log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val)
u, err := url.Parse(attr.Val) u, err := url.Parse(attr.Val)
if err != nil { if err != nil {
return return
@@ -218,6 +223,7 @@ func handleAbsolutePath(attr *html.Attribute, baseURL *url.URL) {
if !(u.Scheme == "http" || u.Scheme == "https") { if !(u.Scheme == "http" || u.Scheme == "https") {
return return
} }
attr.Val = fmt.Sprintf("/%s", escape(strings.TrimPrefix(attr.Val, "/"))) attr.Val = fmt.Sprintf("/%s", escape(strings.TrimPrefix(attr.Val, "/")))
//attr.Val = fmt.Sprintf("/%s", escape(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 //go:embed after_dom_idle_script_injector.js
var afterDomIdleScriptInjector string var afterDomIdleScriptInjector string
func (r *ScriptInjectorRewriter) ModifyToken(token *html.Token) (string, string) { func (r *ScriptInjectorRewriter) ModifyToken(_ *html.Token) (string, string) {
switch { switch {
case r.execTime == BeforeDOMContentLoaded: case r.execTime == BeforeDOMContentLoaded:
return "", fmt.Sprintf("\n<script>\n%s\n</script>\n", r.script) 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 { for key := range params {
keys = append(keys, key) keys = append(keys, key)
} }
sort.Slice(keys, func(i, j int) bool { sort.Slice(keys, func(i, j int) bool {
return len(keys[i]) > len(keys[j]) return len(keys[i]) > len(keys[j])
}) })