improve ruleset unmarshalling behavior if there isnt a top level rule key
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user