improve ruleset unmarshalling behavior if there isnt a top level rule key

This commit is contained in:
Kevin Pham
2023-12-09 08:37:23 -06:00
parent 27c3892b0b
commit 22533dc739
6 changed files with 58 additions and 6 deletions

View File

@@ -52,6 +52,19 @@ func PatchDynamicResourceURLs() proxychain.ResponseModification {
htmlRewriter := rewriters.NewHTMLRewriter(chain.Response.Body, rr)
chain.Response.Body = htmlRewriter
// window.location
/*
spoofedLocationAPI := fmt.Sprintf(`{href:"%s", origin:"%s", pathname:"%s", protocol:"%s:", port:"%s"}`,
reqURL.String(), reqURL.Host,
reqURL.Path, reqURL.Scheme, reqURL.Port())
spoofedLocationAPI := fmt.Sprintf(`{origin: "%s"}`, reqURL.Host)
fmt.Println(spoofedLocationAPI)
chain.AddOnceResponseModifications(
ModifyIncomingScriptsWithRegex(`window\.location`, spoofedLocationAPI),
)
*/
return nil
}
}

View File

@@ -84,6 +84,10 @@ func init() {
return tx.SetIncomingCookie(params[0], params[1])
}
rsmModMap["ModifyIncomingScriptsWithRegex"] = func(params ...string) proxychain.ResponseModification {
return tx.ModifyIncomingScriptsWithRegex(params[0], params[1])
}
rsmModMap["SetResponseHeader"] = func(params ...string) proxychain.ResponseModification {
return tx.SetResponseHeader(params[0], params[1])
}

View File

@@ -33,14 +33,24 @@ func (rs *Ruleset) UnmarshalYAML(unmarshal func(interface{}) error) error {
type AuxRuleset struct {
Rules []Rule `yaml:"rules"`
}
yr := &AuxRuleset{}
yamlRuleset := &AuxRuleset{}
if err := unmarshal(&yr); err != nil {
return err
if err := unmarshal(&yamlRuleset); err != nil {
// if there is no top-level rule key, we'll try to unmarshal as if it is just a bare rule
recovered := false
yamlRule := &Rule{}
if err := unmarshal(&yamlRule); err != nil {
yamlRuleset.Rules = append(yamlRuleset.Rules, *yamlRule)
recovered = true
}
if !recovered {
return err
}
}
rs._rulemap = make(map[string]*Rule)
rs.Rules = yr.Rules
rs.Rules = yamlRuleset.Rules
// create a map of pointers to rules loaded above based on domain string keys
// this way we don't have two copies of the rule in ruleset