Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console Freezes on Incorrect Timestamps in Flows #6646

Open
owlux opened this issue Feb 5, 2024 · 3 comments
Open

Console Freezes on Incorrect Timestamps in Flows #6646

owlux opened this issue Feb 5, 2024 · 3 comments
Labels
kind/triage Unclassified issues

Comments

@owlux
Copy link

owlux commented Feb 5, 2024

Problem Description

I'm using mitmproxy in WireGuard mode for iOS/Android devices. Sometimes, DNS flows are recorded with the request timestamp being later than the response, which causes the console to freeze when these flows are displayed.

Upon encountering this issue, manually rendering the screen using a debugger revealed the following error:

Traceback (most recent call last):
  File "c:\Users\x\Documents\code\y\.venv\lib\site-packages\mitmproxy\tools\console\common.py", line 352, in format_duration
    99 - 100 * min(math.log2(1 + 1000 * duration) / 12, 0.99)
ValueError: math domain error

The problem seems to be from a negative duration value calculated as f.response.timestamp - f.request.timestamp. I suspect this causes the faux_idle_callback() in urwid/main_loop.py not to be called anymore, stopping the screen rendering.

Although format_duration is invoked from various layers, the issue only occurs with DNS flows in my environment. Adjusting a single line in the format_dns_flow() function within mitmproxy\tools\console\common.py resolved the issue.

- if duration:
+ if duration and duration > 0:

The UI freezing during exceptions made it difficult to pinpoint the problem. It would be helpful if there was a way to output errors to a file.

Steps to Reproduce:

  1. Load invalid_timestamp_dns.flow in mitmproxy.
  2. Notice the screen does not render.

invalid_timestamp_dns.zip

System Info

Mitmproxy: 10.2.2
Python: 3.11.7
OpenSSL: OpenSSL 3.1.4 24 Oct 2023
Platform: Windows-10-10.0.22631-SP0

WireGuard for iOS: 1.0.16 (27)

@owlux owlux added the kind/triage Unclassified issues label Feb 5, 2024
@owlux
Copy link
Author

owlux commented Feb 5, 2024

I have not looked into why such timestamps are logged.

@mhils
Copy link
Member

mhils commented Feb 5, 2024

Thanks for filing this! We should fix the root cause here (negative durations) and not apply bandaids.

@mhils
Copy link
Member

mhils commented Feb 5, 2024

More concretely: We currently seem to use client/server-provided timestamps. We shouldn't do that at all, but use local (trusted) timestamps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/triage Unclassified issues
Projects
None yet
Development

No branches or pull requests

2 participants