genotrance / px

An HTTP proxy server to automatically authenticate through an NTLM proxy
MIT License
952 stars 98 forks source link

`_quickjs.JSException: InternalError: Python call failed.` with PAC file #164

Closed mindsolve closed 2 years ago

mindsolve commented 2 years ago

First time user of px here, using px v0.8.3 (frozen windows version) on Windows 10 20H2. My environment uses proxy servers with Kerbers auth (Negotiate).

When trying to use the PAC file, the below error occurs. When not using the PAC file, instead directly specifying the proxy servers, the request through px works flawlessly.

Failing request:

curl --verbose --proxy http://127.0.0.1:3128 --ssl-no-revoke https://servername.companyname.corp

Full debug log (with domain names replaced):

MainProcess: MainThread: 1660825841: /main/parse_config/attach_console: Already attached to a console
MainProcess: MainThread: 1660825841: /main/parse_config/__init__: Proxy mode = MODE_CONFIG_PAC
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: libcurl/7.83.1 OpenSSL/3.0.2 (Schannel) zlib/1.2.12 brotli/1.0.9 libidn2/2.3.2 libssh2/1.10.0 nghttp2/1.47.0 ngtcp2/0.5.0 nghttp3/0.4.1 libgsasl/1.10.0
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_SSL: True
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_SSPI: True
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_SPNEGO: True
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_GSSAPI: False
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_GSSNEGOTIATE: False
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_KERBEROS5: True
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_NTLM: True
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_NTLM_WB: False
MainProcess: MainThread: 1660825841: /parse_config/__init__/print_curl_version: Host: x86_64-pc-win32
Serving at 127.0.0.1:3128 proc MainProcess
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:pac = http://location-pac.internal.companyname.com/proxy.pac
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:listen = 127.0.0.1
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:port = 3128
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:gateway = 0
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:hostonly = 0
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:allow = *.*.*.*
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:noproxy =
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:useragent =
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:auth = ONLYNEGOTIATE
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:server =
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: proxy:username =
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:workers = 2
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:threads = 5
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:idle = 30
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:socktimeout = 20.0
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:proxyreload = 60
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:foreground = 1
MainProcess: MainThread: 1660825841: /main/run_pool/print_banner: settings:log = 1
Process-1: MainThread: 1660825841: /start_worker/parse_config/attach_console: Already attached to a console
Process-1: MainThread: 1660825841: /start_worker/parse_config/__init__: Proxy mode = MODE_CONFIG_PAC
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: libcurl/7.83.1 OpenSSL/3.0.2 (Schannel) zlib/1.2.12 brotli/1.0.9 libidn2/2.3.2 libssh2/1.10.0 nghttp2/1.47.0 ngtcp2/0.5.0 nghttp3/0.4.1 libgsasl/1.10.0
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_SSL: True
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_SSPI: True
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_SPNEGO: True
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_GSSAPI: False
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_GSSNEGOTIATE: False
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_KERBEROS5: True
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_NTLM: True
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: CURL_VERSION_NTLM_WB: False
Process-1: MainThread: 1660825841: /parse_config/__init__/print_curl_version: Host: x86_64-pc-win32
Serving at 127.0.0.1:3128 proc Process-1
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:pac = http://location-pac.internal.companyname.com/proxy.pac
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:listen = 127.0.0.1
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:port = 3128
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:gateway = 0
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:hostonly = 0
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:allow = *.*.*.*
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:noproxy =
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:useragent =
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:auth = ONLYNEGOTIATE
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:server =
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: proxy:username =
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:workers = 2
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:threads = 5
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:idle = 30
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:socktimeout = 20.0
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:proxyreload = 60
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:foreground = 1
Process-1: MainThread: 1660825841: /run/start_worker/print_banner: settings:log = 1
Process-1: MainThread: 1660825845: /serve_forever/_handle_request_noblock/verify_request: Client address: 127.0.0.1
Process-1: Thread_0: 1660825845: /do_CONNECT/do_curl/__init__: a7455e27f5505cd6a9c2f189bf44b5fba9157953: New curl instance
Process-1: Thread_0: 1660825845: /do_curl/__init__/_setup: a7455e27f5505cd6a9c2f189bf44b5fba9157953: CONNECT servername.companyname.corp:443 using HTTP/1.1
Process-1: Thread_0: 1660825845: /handle_one_request/do_CONNECT/do_curl: a7455e27f5505cd6a9c2f189bf44b5fba9157953: Path = servername.companyname.corp:443
Process-1: Thread_0: 1660825845: /find_proxy_for_url/find_proxy_for_url/get_netloc: netloc = ('servername.companyname.corp', 443), path = /
Process-1: Thread_0: 1660825845: /find_proxy_for_url/find_proxy_for_url/__init__: Loading PAC utils
Process-1: Thread_0: 1660825845: /find_proxy_for_url/find_proxy_for_url/load_url: Loading PAC url: http://location-pac.internal.companyname.com/proxy.pac
Process-1: Thread_0: 1660825845: /find_proxy_for_url/load_url/__init__: e0b7f44a2540411f8e03036b6b23da33b5baac0e: New curl instance
Process-1: Thread_0: 1660825845: /load_url/__init__/_setup: e0b7f44a2540411f8e03036b6b23da33b5baac0e: GET http://location-pac.internal.companyname.com/proxy.pac using HTTP/1.1
Process-1: Thread_0: 1660825845: /find_proxy_for_url/load_url/buffer: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Setting up buffers for bridge
Process-1: Thread_0: 1660825845: /load_url/buffer/bridge: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Setting up bridge
Process-1: Thread_0: 1660825845: /perform/do/add: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Handles = 0
Process-1: Thread_0: 1660825845: /do/add/_add_handle: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Add handle
Process-1: Thread_0: 1660825845: /do/add/_add_handle: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Added handle
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Curl info: Trying 10.88.207.18:80...
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Curl info: Connected to location-pac.internal.companyname.com (10.88.207.18) port 80 (#0)
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Sent header => GET /proxy.pac HTTP/1.1
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Sent header => Host: location-pac.internal.companyname.com
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Sent header => Accept: */*
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Curl info: Mark bundle as not supporting multiuse
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Received header <= HTTP/1.1 200 OK
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Received header <= Connection: close
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Received header <= Content-Type: application/x-ns-proxy-autoconfig
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Received header <= Content-Length: 14759
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_header_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Done sending headers
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_write_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Wrote 14759 bytes
Process-1: Thread_0: 1660825845: /_perform/_socket_action/_debug_callback: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Curl info: Closing connection 0
Process-1: Thread_0: 1660825845: /perform/remove/_remove_handle: e0b7f44a2540411f8e03036b6b23da33b5baac0e: Remove handle:
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 52112)
Traceback (most recent call last):
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\socketserver.py", line 683, in process_request_thread
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\socketserver.py", line 360, in finish_request
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\socketserver.py", line 747, in __init__
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\http\server.py", line 425, in handle
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\main.py", line 295, in handle_one_request
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\http\server.py", line 413, in handle_one_request
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\main.py", line 392, in do_CONNECT
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\main.py", line 325, in do_curl
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\main.py", line 399, in get_destination
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\wproxy.py", line 465, in find_proxy_for_url
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\wproxy.py", line 256, in find_proxy_for_url
  File "C:\Users\mindsolve\PROGRA~1\PX-V08~1.3\px\pac.py", line 60, in find_proxy_for_url
_quickjs.JSException: InternalError: Python call failed.
    at FindProxyForURL (<input>:27)

----------------------------------------

The configuration:

[proxy]
pac = http://location-pac.internal.companyname.com/proxy.pac
listen = 127.0.0.1
port = 3128
gateway = 0
hostonly = 0
allow = *.*.*.*
noproxy =
useragent =
auth = ONLYNEGOTIATE
[settings]
workers = 2
threads = 5
idle = 30
socktimeout = 20.0
proxyreload = 60
foreground = 1
log = 1

If the line in the error message represents the line in the pac file, here is the surrounding text from that: Note: the only replaced values are 10.10.10.10 and 10.10.10.11. I think this is for load-balancing?

[...]
function FindProxyForURL(url, host) {

    if(isInNet(myIpAddress(), "0.0.0.1", "0.0.0.1")){
        LEGPROXY = "PROXY 10.10.10.10:8080; PROXY 10.10.10.11:8080";
    }else{
        LEGPROXY = "PROXY 10.10.10.11:8080; PROXY 10.10.10.10:8080";
    }
[...]

If the full PAC file is needed, please say so (the file is quite long/complex and might take a while to redact/compress down).

Thanks!

genotrance commented 2 years ago

I suspect it is failing in the myIpAddress() call which maps back into Python.

https://github.com/genotrance/px/blob/39df09c98d9dc768e020f56f140c2b8b85efc828/px/pac.py#L87-L89

Can you try putting in some debug there, or perhaps returning a hard-coded value?