crossbario / crossbario/autobahn-python

proxy port is ignored by asyncio ApplicationRunner

Open
#1,251 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

Steps to Reproduce

  1. Use asyncio
  2. Use the old ApplicationRunner API
  3. Pass the proxy kwarg with host and port where port != 443
  4. Invoke sample code thusly: sample.py wss://myrouter.com/ws realm1 myproxy.com:3128

Expected Result

autobahn connects successfully

Actual Result

dropping connection to peer tcp4:10.1.6.95:443 with abort=True: None

(notice I specified port 3128)

Sample Code

import sys
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
import txaio

txaio.start_logging( level = 'debug' )

class Application( ApplicationSession ):
    def onJoin( self, details ):
        print( 'joined session' )

proxy_host, proxy_port = sys.argv[3].split( ':' )

runner = ApplicationRunner(
    sys.argv[1],
    sys.argv[2],
    proxy = dict(
        host = proxy_host,
        port = int( proxy_port )
    ),
)

runner.run( Application )

Notes

2019-09-27T14:59:27                                                                                                                                                                            
[('logOctets', False, 'WampWebSocketClientFactory'),                                                                                                                                           
 ('logFrames', False, 'WampWebSocketClientFactory'),                                                                                                                                           
 ('trackTimings', False, 'WampWebSocketClientFactory'),                
 ('utf8validateIncoming', True, 'WampWebSocketClientFactory'),
 ('applyMask', True, 'WampWebSocketClientFactory'),
 ('maxFramePayloadSize', 1048576, 'WampWebSocketClientFactory'),
 ('maxMessagePayloadSize', 1048576, 'WampWebSocketClientFactory'),
 ('autoFragmentSize', 65536, 'WampWebSocketClientFactory'),
 ('failByDrop', False, 'WampWebSocketClientFactory'),
 ('echoCloseCodeReason', False, 'WampWebSocketClientFactory'),
 ('openHandshakeTimeout', 2.5, 'WampWebSocketClientFactory'),
 ('closeHandshakeTimeout', 1, 'WampWebSocketClientFactory'),
 ('tcpNoDelay', True, 'WampWebSocketClientFactory'),
 ('autoPingInterval', 10.0, 'WampWebSocketClientFactory'),
 ('autoPingTimeout', 5.0, 'WampWebSocketClientFactory'),
 ('autoPingSize', 4, 'WampWebSocketClientFactory'),
 ('version', 18, 'WampWebSocketClientFactory'),
 ('acceptMaskedServerFrames', False, 'WampWebSocketClientFactory'),
 ('maskClientFrames', True, 'WampWebSocketClientFactory'),
 ('serverConnectionDropTimeout', 1, 'WampWebSocketClientFactory'),
 ('perMessageCompressionOffers',
  [PerMessageDeflateOffer(accept_no_context_takeover = True, accept_max_window_bits = True, request_no_context_takeover = False, request_max_window_bits = 0)],
  'WampWebSocketClientFactory'),
 ('perMessageCompressionAccept',
  <function ApplicationRunner.run.<locals>.accept at 0x7f53e8d8ab70>,
  'WampWebSocketClientFactory')]                                                                                                                                                               
2019-09-27T14:59:27 connection to tcp4:10.1.6.95:443 established
2019-09-27T14:59:27 CONNECT redacted.company.com:443 HTTP/1.1
Host: redacted.company.com:443


2019-09-27T14:59:27 received HTTP response:

b'HTTP/1.1 400 Bad Request\r\nServer: nginx\r\nDate: Fri, 27 Sep 2019 18:59:27 GMT\r\nContent-Type: text/html\r\nContent-Length: 150\r\nConnection: close\r\nX-Frame-Options: SAMEORIGIN\r\nX-X
SS-Protection: 1; mode=block\r\n\r\n'


2019-09-27T14:59:27 received HTTP status line for proxy connect request : HTTP/1.1 400 Bad Request
2019-09-27T14:59:27 received HTTP headers for proxy connect request : {'server': 'nginx', 'date': 'Fri, 27 Sep 2019 18:59:27 GMT', 'content-type': 'text/html', 'content-length': '150', 'conne
ction': 'close', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block'}
2019-09-27T14:59:27 failing proxy connect ('HTTP proxy connect failed (400 - BadRequest)')
2019-09-27T14:59:27 dropping connection to peer tcp4:10.1.6.95:443 with abort=True: None
2019-09-27T14:59:27 _connectionLost: None

Notice the line

2019-09-27T14:59:27 connection to tcp4:10.1.6.95:443 established

It's taking my host option, but assuming port 443 even though I said port 3128. Something else on that box (nginx) is listening on 443 and responds with http 400 because it isn't a proxy.

Note that this works in twisted. Change the import to autobahn.twisted.wamp and you'll get the Expected Result.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the asyncio ApplicationRunner entry point and trace how the proxy host and port are passed into the connection setup; compare this with the working twisted.wamp path. Verify the sample using myproxy.com:3128 connects to the proxy on port 3128 rather than defaulting to 443.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.