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

puppet module install breaks on HTTP redirects. #9143

Closed
defnull opened this issue Nov 4, 2023 · 3 comments · Fixed by #9265
Closed

puppet module install breaks on HTTP redirects. #9143

defnull opened this issue Nov 4, 2023 · 3 comments · Fixed by #9265
Labels
bug Something isn't working triaged Jira issue has been created for this

Comments

@defnull
Copy link

defnull commented Nov 4, 2023

Describe the Bug

Calling puppet module install or any other code that internally uses Puppet::HTTP::Client may break with obscure invalid encoding:"783: unexpected token at '\x1F\x8B\b'" or similar errors if HTTP redirects are involved and the final server supports HTTP compression.

This is caused by Puppet::HTTP::Redirector internally used by Puppet::HTTP::Client to follow HTTP redirects. The redirect logic copies all request headers from the original Net::HTTPRequest object to a new one, including an Accept-Encoding header that was implicitly added by Net::HTTP during the first request.

Net::HTTP supports HTTP compression. It will automatically add an Accept-Encoding header and later decompress the response body, but only if that header was not already set by the caller. Puppet::HTTP::Redirector adds this header explicitly, disabling the transparent compression handling in Net::HTTP and resulting in a response body that may contain gzip compressed binary data instead of the expected result.

Feeding gzip compressed binary data into a JSON decoder triggers the unexpected token at '\x1F\x8B\b' error from above.

Expected Behavior

HTTP redirects should be handled gracefully and not cause obscure errors.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Run puppet module install --module_repository http://forge.puppetlabs.com puppetlabs-stdlib
  2. The redirect from http to https will trigger the error.

Environment

  • Version: 7 and 8
  • Platform: any
@defnull defnull added the bug Something isn't working label Nov 4, 2023
@joshcooper joshcooper added the triaged Jira issue has been created for this label Nov 6, 2023
Copy link

github-actions bot commented Nov 6, 2023

Migrated issue to PUP-11983

@joshcooper
Copy link
Contributor

Thanks @defnull, we can reproduce as well. One option is to exclude the Accept-Encoding header when creating the new request:

request.each do |header, value|

Or possibly passing down a set of headers to be set on the new request:

request = redirector.redirect_to(request, response, redirects)

See also a23ee91

@defnull
Copy link
Author

defnull commented Nov 25, 2023

I think excluding Accept-Encoding when copying the old headers to the new request is the way to go. That's probably the easiest solution and does not require changes in any of the internal APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged Jira issue has been created for this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants