Developing and testing features or extensions for Microsoft Edge
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
Developing and testing features or extensions for Microsoft Edge
AI answer
To trace and block unauthorized ad injections, use a combination of Microsoft Edge DevTools network inspection and a strict Content Security Policy.
F12 or Ctrl+Shift+I to open DevTools.This process lets the exact script file, inline script, or third‑party domain responsible for the ads be identified.
Content Security Policy can prevent unauthorized scripts and iframes from loading at all.
Recommended approach when tightening CSP:
Content-Security-Policy-Report-Only header so that violations are logged but not blocked.script-src directive that includes only:
'self' (your own domain)style-src, img-src, frame-src/child-src to trusted domains only.Content-Security-Policy header.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.
frame-src/child-src to limit which domains can be framed.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:
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.