Skip to content

Browser HTML conversion can leak global html2text monkey patches after an exception #296

Description

@sylvesterkaczmarek

Summary

gpt_oss.tools.simple_browser.page_contents.html_to_text() temporarily replaces the module-level html2text.utils.escape_md and escape_md_section functions, calls HTML2Text.handle(), and restores them afterward.

The restoration is not protected by finally, and the global mutation is not synchronized. If conversion raises, the patched functions remain installed process-wide. Concurrent conversions can also observe or overwrite each other's temporary global state.

Impact

One malformed/problematic page can permanently change later html2text behavior in the process. Concurrent browser fetches can also race on the shared html2text globals, making page conversion order-dependent.

Proposed resolution

Guard the temporary monkey patch with a module-level lock and restore the original functions in finally. Add regression coverage that forces HTML2Text.handle() to raise and verifies both globals are restored.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions