fix nil pointer deref
This commit is contained in:
@@ -39,19 +39,21 @@ type ProxyOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
||||||
var rs ruleset.RuleSet
|
/*
|
||||||
if opts.RulesetPath != "" {
|
var rs ruleset.RuleSet
|
||||||
r, err := ruleset.NewRuleset(opts.RulesetPath)
|
if opts.RulesetPath != "" {
|
||||||
if err != nil {
|
r, err := ruleset.NewRuleset(opts.RulesetPath)
|
||||||
panic(err)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
rs = r
|
||||||
}
|
}
|
||||||
rs = r
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
return proxychain.NewProxyChain().
|
return proxychain.NewProxyChain().
|
||||||
SetCtx(c).
|
SetCtx(c).
|
||||||
AddRuleset(&rs).
|
//AddRuleset(&rs).
|
||||||
SetRequestModifications(
|
SetRequestModifications(
|
||||||
rqm.BlockOutgoingCookies(),
|
rqm.BlockOutgoingCookies(),
|
||||||
).
|
).
|
||||||
|
|||||||
@@ -214,6 +214,12 @@ func (chain *ProxyChain) _execute() (*[]byte, error) {
|
|||||||
chain.Body = body
|
chain.Body = body
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
/* todo: move to rsm
|
||||||
|
for k, v := range resp.Header {
|
||||||
|
chain.Context.Set(k, resp.Header.Get(k))
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Apply ResponseModifiers to proxychain (pxc)
|
// Apply ResponseModifiers to proxychain (pxc)
|
||||||
for _, applyResultModificationsTo := range chain.resultModifications {
|
for _, applyResultModificationsTo := range chain.resultModifications {
|
||||||
err := applyResultModificationsTo(chain)
|
err := applyResultModificationsTo(chain)
|
||||||
@@ -348,37 +354,37 @@ func (pxc *ProxyChain) SetClient(httpClient *http.Client) *ProxyChain {
|
|||||||
|
|
||||||
// SetVerbose changes the logging behavior to print
|
// SetVerbose changes the logging behavior to print
|
||||||
// the modification steps and applied rulesets for debugging
|
// the modification steps and applied rulesets for debugging
|
||||||
func (pxc *ProxyChain) SetVerbose() *ProxyChain {
|
func (chain *ProxyChain) SetVerbose() *ProxyChain {
|
||||||
pxc.verbose = true
|
chain.verbose = true
|
||||||
return pxc
|
return chain
|
||||||
}
|
}
|
||||||
|
|
||||||
// abort proxychain and return 500 error to client
|
// abort proxychain and return 500 error to client
|
||||||
// this will prevent Execute from firing and reset the state
|
// this will prevent Execute from firing and reset the state
|
||||||
// returns the initial error enriched with context
|
// returns the initial error enriched with context
|
||||||
func (pxc *ProxyChain) abort(err error) error {
|
func (chain *ProxyChain) abort(err error) error {
|
||||||
defer pxc._reset()
|
defer chain._reset()
|
||||||
pxc._abort_err = err
|
chain._abort_err = err
|
||||||
pxc.Context.Response().SetStatusCode(500)
|
chain.Context.Response().SetStatusCode(500)
|
||||||
e := fmt.Errorf("ProxyChain error for '%s': %s", pxc.Request.URL.String(), err.Error())
|
e := fmt.Errorf("ProxyChain error for '%s': %s", chain.Request.URL.String(), err.Error())
|
||||||
pxc.Context.SendString(e.Error())
|
chain.Context.SendString(e.Error())
|
||||||
log.Println(e.Error())
|
log.Println(e.Error())
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal function to reset state of ProxyChain for reuse
|
// internal function to reset state of ProxyChain for reuse
|
||||||
func (pxc *ProxyChain) _reset() {
|
func (chain *ProxyChain) _reset() {
|
||||||
pxc._abort_err = nil
|
chain._abort_err = nil
|
||||||
pxc.Body = nil
|
chain.Body = nil
|
||||||
pxc.Request = nil
|
chain.Request = nil
|
||||||
pxc.Response = nil
|
chain.Response = nil
|
||||||
pxc.Context = nil
|
chain.Context = nil
|
||||||
pxc.Request.URL = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProxyChain initializes a new ProxyChain
|
// NewProxyChain initializes a new ProxyChain
|
||||||
func NewProxyChain() *ProxyChain {
|
func NewProxyChain() *ProxyChain {
|
||||||
px := new(ProxyChain)
|
chain := new(ProxyChain)
|
||||||
px.Client = defaultClient
|
//px.Client = defaultClient
|
||||||
return px
|
chain.Client = http.DefaultClient
|
||||||
|
return chain
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user