## Unreleased: mitmproxy next
+- Fix mitmweb auth cookie always using the default `web_port` option.
+ ([#7827](https://github.com/mitmproxy/mitmproxy/pull/7827), @sujaldev)
- fix: missing content-length header in curl export
([#7810](https://github.com/mitmproxy/mitmproxy/pull/7810), @mheguy)
- fix: update log message with correct header name
self.auth_fail(bool(password))
return None
self.set_signed_cookie(
- self.settings["auth_cookie_name"],
+ self.settings["auth_cookie_name"](),
self.AUTH_COOKIE_VALUE,
expires_days=400,
httponly=True,
def get_current_user(self) -> bool:
return (
- self.get_signed_cookie(self.settings["auth_cookie_name"], min_version=2)
+ self.get_signed_cookie(self.settings["auth_cookie_name"](), min_version=2)
== self.AUTH_COOKIE_VALUE
)
autoreload=False,
transforms=[GZipContentAndFlowFiles],
is_valid_password=auth_addon.is_valid_password,
- auth_cookie_name=f"mitmproxy-auth-{master.options.web_port}",
+ auth_cookie_name=auth_addon.auth_cookie_name,
)
# noinspection HttpUrlsUsage
return f"http://{ctx.options.web_host}:{ctx.options.web_port}/{auth}"
+ @staticmethod
+ def auth_cookie_name() -> str:
+ return f"mitmproxy-auth-{ctx.options.web_port}"
+
def is_valid_password(self, password: str) -> bool:
if self._password.startswith("$"):
try:
def auth_cookie(self) -> str:
auth_cookie = create_signed_value(
secret=self._app.settings["cookie_secret"],
- name=self._app.settings["auth_cookie_name"],
+ name=self._app.settings["auth_cookie_name"](),
value=app.AuthRequestHandler.AUTH_COOKIE_VALUE,
).decode()
- return f"{self._app.settings['auth_cookie_name']}={auth_cookie}"
+ return f"{self._app.settings['auth_cookie_name']()}={auth_cookie}"
def fetch(self, *args, **kwargs) -> httpclient.HTTPResponse:
kwargs.setdefault("headers", {}).setdefault("Cookie", self.auth_cookie)
assert e.code == 403
else:
assert False
+
+ def test_auth_cookie_port_suffix_modification(self):
+ opts = self.master.options
+
+ old_port = opts.web_port
+ new_port = 8082
+ opts.web_port = new_port
+
+ try:
+ assert self._app.settings["auth_cookie_name"]().endswith(str(new_port))
+ finally:
+ opts.web_port = old_port