Rule Definition
UA sniffing is brittle and discouraged; IE-specific checks (MSIE, Trident, old Edge) are legacy.
Remediation
Use feature detection (e.g., checking if a method exists) or standards-based behavior; avoid IE-only branches.
Violation Code Sample
var ua = navigator.userAgent;
if (ua.indexOf("MSIE") !== -1 || ua.indexOf("Trident") !== -1) {
// IE-specific logic
useLegacyStuff();
}
Fixed Code Sample
if ("fetch" in window) {
modernImplementation();
} else {
fallbackImplementation();
}
Reference
– MDN – Browser detection using the user agent: https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
– MDN – navigator.userAgent: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent
Related Technologies
Technical Criterion
CWE-710 - Improper Adherence to Coding Standards [Pillar]
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.