digital-analytics-program / gov-wide-code

Provides a set of javascript files and documentation to implement web analytics on US federal websites
http://www.digital.gov/dap
104 stars 55 forks source link

Fix code scanning alert no. 16: Incomplete URL substring sanitization #135

Closed levinmr closed 1 month ago

levinmr commented 1 month ago

Fixes https://github.com/digital-analytics-program/gov-wide-code/security/code-scanning/16

To fix the problem, we need to parse the URL and check its host component to ensure it matches the expected value. This approach will prevent bypassing the check by embedding the target string in different parts of the URL.

  1. Parse the URL using the URL constructor to extract the host component.
  2. Compare the host component against the expected value (www.google-analytics.com).
  3. Ensure the path component matches the expected path (/g/collect).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.