PAC-B005 · repeated-proxy-string-literal

Same proxy string repeated many times

info · Best practice and maintainability

Writing "PROXY proxy.corp.example:8080" in a dozen places means a dozen edits when the proxy moves and a dozen chances for a typo in one of them.

Why it matters

Proxy addresses change (migrations, failover redesign, port changes). When the literal is repeated, one missed occurrence sends part of the traffic to the old address and the difference is only noticed when that proxy is decommissioned. A top-level var makes the change atomic and makes the file’s routing targets visible at a glance.

How to fix

var PROXY = "PROXY proxy.corp.example:8080"; and return PROXY everywhere.

Examples

Bad

function FindProxyForURL(url, host) {
  if (dnsDomainIs(host, ".corp.example")) { return "DIRECT"; }
  if (dnsDomainIs(host, ".partner.example")) { return "PROXY proxy.corp.example:8080"; }
  if (dnsDomainIs(host, ".lab.example")) { return "PROXY proxy.corp.example:8080"; }
  return "PROXY proxy.corp.example:8080";
}
Open bad example in checker

Good

var PROXY = "PROXY proxy.corp.example:8080";
function FindProxyForURL(url, host) {
  if (dnsDomainIs(host, ".corp.example")) { return "DIRECT"; }
  return PROXY;
}
Open good example in checker

Related rules