How to identify and block unauthorized ad injections on my website?

peter zou 0 Reputation points
2026-06-15T10:09:57.7666667+00:00

Hi Microsoft Community,

I am the developer/webmaster of the website (Link removed by Moderator. Do not recreate.). Recently, I noticed that some unexpected and unwanted ads are appearing on my site, which I did not manually implement. I suspect it might be a third-party script injection or a compromised proxy.

I would like to ask for your technical advice:

How can I effectively use Microsoft Edge Developer Tools (F12) to trace the network requests and find the exact source script that is injecting these ads?

Are there any recommended practices using Content Security Policy (CSP) to strictly block these unauthorized third-party ad domains?

Any guidance on network tracing or security configurations would be greatly appreciated!

Thank you in advance.

Microsoft Edge | Microsoft Edge development
0 comments No comments

2 answers

Sort by: Newest
  1. Damien Pham (WICLOUD CORPORATION) 2,135 Reputation points Microsoft External Staff Moderator
    2026-06-17T10:12:05.1366667+00:00

    Hello @peter zou ,

    I understand why this is concerning. In Edge DevTools, the fastest way to trace this is to open the page with DevTools already running, go to the Network tool, refresh the page, and then filter to likely resources such as JS/XHR. I recommend enabling the Domain and Initiator columns as well, because the Initiator column in the Network tool links back to the script or source code that triggered the request, which is usually the quickest way to find whether the ads are coming from an injected script, a third-party tag, or an upstream rewrite.

    After you identify a suspicious request, you can confirm it by right-clicking that request and using Block request URL or Block request domain, then reloading the page. If the ads disappear, that request or domain is part of the injection path.

    For CSP, I recommend moving toward a strict allowlist policy: allow only your own origin and the exact third-party domains you trust for directives such as script-src and frame-src, avoid broad wildcards, start in report-only mode first, and then enforce once you have verified the legitimate resources your site needs.

    I hope this helps. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.    

    Thank you.    

     

    Was this answer helpful?


  2. AI answer

    2026-06-15T10:10:15.39+00:00

    To trace and block unauthorized ad injections, use a combination of Microsoft Edge DevTools network inspection and a strict Content Security Policy.

    1. Use Edge DevTools to find the ad-injecting script
    2. Open the site in Microsoft Edge.
    3. Press F12 or Ctrl+Shift+I to open DevTools.
    4. Go to the Network tab.
    5. Reload the page with DevTools open so all requests are captured.
    6. Look for suspicious requests:
      • Filter by JS or Script to see all JavaScript files.
      • Also check XHR/Fetch requests that may load ad content or iframes.
      • Sort by Domain/Name and look for unknown ad, tracking, or CDN domains that you did not configure.
    7. For each suspicious request:
      • Select it and inspect the Initiator/Stack (or Headers → Referer and Initiator) to see which script or HTML element triggered it.
      • This shows the original script file or inline script that is causing the ad request.
    8. If needed, temporarily block a suspected domain or URL to confirm:
      • In the Network tab, right‑click the suspicious request → Block request URL or Block request domain. This uses the Network request blocking feature.
      • Reload the page. If the ads disappear, that domain or URL is part of the injection chain.

    This process lets the exact script file, inline script, or third‑party domain responsible for the ads be identified.

    1. Use Content Security Policy (CSP) to block unauthorized ad domains

    Content Security Policy can prevent unauthorized scripts and iframes from loading at all.

    Recommended approach when tightening CSP:

    1. Start in report-only mode:
      • Configure a Content-Security-Policy-Report-Only header so that violations are logged but not blocked.
      • Load the site in Edge and check the Console in DevTools for CSP violation messages.
      • These messages show which external scripts, iframes, or resources are being loaded and from which domains.
    2. Whitelist only trusted sources:
      • For scripts, use a restrictive script-src directive that includes only:
        • 'self' (your own domain)
        • Any known, trusted CDNs or service domains actually needed.
      • For styles, images, frames, etc., similarly restrict style-src, img-src, frame-src/child-src to trusted domains only.
    3. Iterate based on violations:
      • From the Console CSP violation logs, add only the domains that are legitimate site functionality.
      • Do not add ad or tracking domains that were identified as unwanted in the Network tab.
    4. Switch to enforcement mode:
      • Once no critical functionality is blocked in report-only mode, move the policy to the enforcing Content-Security-Policy header.
      • At this point, any ad-injecting third‑party domains not on the allowlist will be blocked by the browser.

    For example, a strict baseline policy for scripts might resemble the default Power Pages policy:

    Content-Security-Policy: script-src 'self' 'nonce-…'; style-src 'unsafe-inline' https:;
    

    In a custom site, extend script-src only with the specific trusted domains actually used. Avoid wildcards like * or overly broad sources such as https: unless absolutely necessary.

    1. Additional hardening steps
    • Use HTTPS with a valid certificate and avoid mixed content; this reduces the risk of content being modified in transit.
    • Block iframes from loading unknown third‑party content and use CSP frame-src/child-src to limit which domains can be framed.
    • Regularly scan the hosting environment for WebShells, trojans, or suspicious uploaded files that might be injecting scripts server-side.
    • Maintain stable hosting and DNS to preserve domain reputation and reduce SmartScreen or reputation-related issues.

    Combining DevTools network tracing (to identify the exact ad domains and scripts) with a strict, iteratively tuned CSP (to allow only known-good sources) is an effective way to detect and block unauthorized ad injections.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.