BlackSheep icon indicating copy to clipboard operation
BlackSheep copied to clipboard

ForwardedHeadersMiddleware - no ability to configure accept_only_proxied_requests

Open mavwolverine opened this issue 2 years ago • 1 comments

Describe the bug A description of what the bug is, possibly including how to reproduce it.

The flag, accept_only_proxied_requests, is hardcoded to True https://github.com/Neoteroi/BlackSheep/blob/a3656fb7eb0dbb9582f276bf1a61d4d14bbcb077/blacksheep/server/remotes/forwarding.py#L46

Override should be allowed in the constructor.

Would be useful in cloud where load balancer will be used, but monitoring scripts would use the instance local ip.

mavwolverine avatar Aug 16 '22 15:08 mavwolverine

Hi! Thank You for reporting this issue. You are right that the class should allow configuring that property in the constructor, this can be easily fixed.

It is not a blocking bug, though, as it's always possible to set the property after instantiating the class:

@app.on_middlewares_configuration
def configure_forwarded_headers(app):
    forward_middleware = ForwardedHeadersMiddleware()
    forward_middleware.accept_only_proxied_requests = False

    app.middlewares.insert(
        0,
        forward_middleware,
    )

instead of:

@app.on_middlewares_configuration
def configure_forwarded_headers(app):
    app.middlewares.insert(
        0,
        ForwardedHeadersMiddleware(),
    )

RobertoPrevato avatar Aug 18 '22 21:08 RobertoPrevato