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

% in error message being encoded into %% (by Tornado HTTPError) #1503

Open
ptch314 opened this issue Feb 26, 2025 · 0 comments
Open

% in error message being encoded into %% (by Tornado HTTPError) #1503

ptch314 opened this issue Feb 26, 2025 · 0 comments
Labels

Comments

@ptch314
Copy link

ptch314 commented Feb 26, 2025

Description

We have a use case where the server is expected in some cases to return a “400 Bad Request” response with a message that includes a URL-encoded string. However, the URL-encoded text unexpectedly comes back with all %s being transformed into %%s. We want to know if this is a bug in Jupyter, a bug in a Jupyter dependency (Tornado), or expected behavior that we need to work around.

Reproduce

The issue is difficult to reproduce without running a server that returns an error message with % characters in the HTTP response.

To elaborate, the %s come from us wanting to return an error message with a nested, URL-encoded URL that already has encoded symbols, such as https://example.com/?redirect=http%3A%2F%2F. But because of the issue, they are being returned as https://example.com/?redirect=http%%3A%%2F%%2F instead.

Context

  • Operating System and version: N/A
  • Browser and version: N/A
  • Jupyter Server version: v2.15.0

We looked into the Jupyter Server source code, and identified the root cause is likely

raise web.HTTPError(
e.code,
f"Error from Gateway: [{error_message}] {error_reason}. "
"Ensure gateway url is valid and the Gateway instance is running.",
) from e
, where it is calling the HTTPError constructor with an f-string log_message argument to inject placeholder values instead of using the syntax expected by Tornado of %s in log_message and placeholder values in the args. This is compounded by Tornado encoding all %s in the log_message (but not in the args) into %%s.

https://www.tornadoweb.org/en/stable/_modules/tornado/web.html#HTTPError

        if log_message and not args:
            self.log_message = log_message.replace("%", "%%")
@ptch314 ptch314 added the bug label Feb 26, 2025
hXtreme added a commit to hXtreme/tornado that referenced this issue Feb 27, 2025
Attempts to fix the [jupyter_server/issues/1503](jupyter-server/jupyter_server#1503) issue
hXtreme added a commit to hXtreme/tornado that referenced this issue Feb 27, 2025
Attempts to fix the [jupyter_server/issues/1503](jupyter-server/jupyter_server#1503) issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant