Proxy Auto Configuration for Dummies: Troubleshooting Common Problems
What is a PAC file?
A PAC (Proxy Auto-Configuration) file is a JavaScript file that tells a browser which proxy to use for each URL. It contains a single function, FindProxyForURL(url, host), that returns proxy directives like “DIRECT” or “PROXY host:port”.
Common problem 1 — Browser ignores the PAC file
- Likely causes: Incorrect PAC URL, network policy override, browser caching, or syntax error in the PAC file.
- Quick fixes:
- Validate PAC URL: Open the PAC file URL in the browser; you should see plain text JavaScript.
- Clear browser/policy cache: Restart browser and flush OS proxy settings (e.g., Windows: netsh winhttp reset proxy).
- Check for group policy or MDM: Confirm no enterprise policy forces a different proxy.
- Test in another browser or device to isolate browser vs. network issue.
Common problem 2 — PAC file syntax or logic errors
- Likely causes: Missing semicolons, unescaped strings, incorrect return values, runtime exceptions.
- Quick fixes:
- Use a PAC linter/validator (online tools) to find syntax errors.
- Wrap code in try/catch to prevent uncaught exceptions from stopping the function.
- Simplify logic to isolate the failing branch—return a simple fixed value like “DIRECT” to confirm basic operation.
- Test FindProxyForURL manually in a JS console or using curl to fetch the file and evaluate behavior locally.
Common problem 3 — PAC file not updated due to caching
- Likely causes: Browser or proxy caching, CDN caching, or aggressive TTL headers.
- Quick fixes:
- Set HTTP headers on the PAC file server: Cache-Control: no-cache, must-revalidate.
- Append version query string to PAC URL (e.g., pacfile.pac?v=20260205) when deploying updates.
- Restart browsers and clients or clear DNS/proxy caches where possible.
Common problem 4 — PAC rules misroute traffic or cause connectivity failures
- Likely causes: Wrong pattern matching, incorrect host checks, or proxy unreachable.
- Quick fixes:
- Log decisions: Temporarily add code to return different proxies for known hosts to test (or have the function call myIpAddress() for debugging).
- Verify pattern matching: Use shExpMatch, dnsDomainIs, isInNet correctly and test edge cases.
- Ensure fallback: Always include a fallback like “DIRECT” if preferred proxies fail.
- Check proxy health: Ensure the proxy server accepts connections on the specified port.
Common problem 5 — DNS or isInNet inconsistencies
- Likely causes: Clients resolve DNS differently; isInNet uses numeric IPs and masks.
- Quick fixes:
- Resolve hostnames to IPs and verify isInNet(ip, mask) inputs are correct.
- Use dnsDomainIs or shExpMatch when possible instead of isInNet if DNS varies.
- Avoid relying on client-side DNS for critical routing decisions if clients are on different networks.
How to debug step-by-step
- Confirm PAC file is reachable: Paste PAC URL in browser.
- Test a simple return: Temporarily change to return “DIRECT” or “PROXY 1.2.3.4:8080”.
- Check browser dev tools / logs: Some browsers show proxy decision logs (e.g., Chrome net-internals).
- Compare client behavior: Try another device or network to narrow scope.
- Inspect HTTP headers and caching: Ensure server serves updated file.
- Roll back to known-good PAC if recent changes introduced issues.
Best practices to avoid problems
- Keep PAC simple and well-commented.
- Host PAC on a reliable server with proper cache headers.
- Version PAC URLs for quick rollbacks.
- Test changes in a staging group before wide deployment.
- Monitor proxy health and have clear fallbacks like “DIRECT”.
Quick reference: common PAC return values
- DIRECT — connect without a proxy.
- PROXY host:port — use specified proxy.
- SOCKS host:port — use a SOCKS proxy.
- PROXY host1:port; PROXY host2:port; DIRECT — try host1, then host2, then direct.
If you want, I can: validate a PAC file you provide, produce a minimal example PAC that covers common needs, or create a checklist for deployment.
Leave a Reply