fix(frameworks): stop prose and image mime types from faking magento (#322)

the bare "Magento" body word matched any page that merely named the
platform, and "mage/" is a substring of the near-ubiquitous "image/"
mime type, so a migration guide carrying a single image reference
scored both signatures and cleared the detection threshold. key on the
frontend static-asset base, the data-mage-init widget attribute and the
module namespace, which only appear when magento actually rendered the
page.

Co-authored-by: vmfunc <vmfunc.lc@gmail.com>
This commit is contained in:
Tigah
2026-07-22 22:10:21 +00:00
committed by GitHub
co-authored by vmfunc
parent a09643c070
commit 7d206ad033
2 changed files with 7 additions and 2 deletions
@@ -39,6 +39,7 @@ func TestDetectorAccuracy_FalsePositives(t *testing.T) {
{"Shopify cdn body only", &shopifyDetector{}, `<script src="https://cdn.shopify.com/s/buy-button.js"></script>`, http.Header{}},
{"Spring Boot tutorial prose", &springBootDetector{}, `<article>To fix the Whitelabel Error Page in Spring Boot, add a controller.</article>`, http.Header{}},
{"Remix audio asset", &remixDetector{}, `<audio src="/audio/track_remix.mp3"></audio>`, http.Header{}},
{"Magento migration guide with image mime", &magentoDetector{}, `<article><h1>How to migrate your Magento store</h1><img src="/logo.png" type="image/png"> A guide to Magento 2.</article>`, http.Header{}},
{"Gatsby plugin comparison prose", &gatsbyDetector{}, `<article>gatsby-image and gatsby-plugin-sharp used to be the standard way to handle images before gatsby-plugin-image.</article>`, http.Header{}},
{"Svelte ecosystem comparison prose", &svelteDetector{}, `<article>popular svelte-native and svelte-check tools round out the ecosystem.</article>`, http.Header{}},
}
@@ -64,6 +65,7 @@ func TestDetectorAccuracy_TruePositives(t *testing.T) {
{"Shopify storefront header", &shopifyDetector{}, "", accHeader("X-Shopify-Stage", "production")},
{"Spring Boot whitelabel page", &springBootDetector{}, `<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error</p><div>There was an unexpected error (type=Not Found, status=404).</div></body></html>`, http.Header{}},
{"Remix context", &remixDetector{}, `<script>window.__remixContext = {"state":{}};</script>`, http.Header{}},
{"Magento storefront markup", &magentoDetector{}, `<html><head><link rel="stylesheet" href="/static/frontend/Magento/luma/en_US/css/styles.css"></head><body data-mage-init='{"cookieStatus": {}}'></body></html>`, http.Header{}},
{"Gatsby root div and page-data", &gatsbyDetector{}, `<html><body><div id="___gatsby"><script src="/page-data/index/page-data.json"></script></div></body></html>`, http.Header{}},
{"Svelte runtime global and internal import", &svelteDetector{}, `<script>window.__svelte = {}; import { onMount } from "svelte/internal";</script>`, http.Header{}},
}
+5 -2
View File
@@ -120,11 +120,14 @@ type magentoDetector struct{}
func (d *magentoDetector) Name() string { return "Magento" }
func (d *magentoDetector) Signatures() []fw.Signature {
// "Magento" matched mere prose, and "mage/" matched the "image/" mime
// type, together clearing the threshold on unrelated pages. key on
// structural markers that only appear when Magento actually rendered.
return []fw.Signature{
{Pattern: "Magento", Weight: 0.4},
{Pattern: "/static/frontend/", Weight: 0.4},
{Pattern: "mage/", Weight: 0.3},
{Pattern: "data-mage-init", Weight: 0.4},
{Pattern: "Mage.Cookies", Weight: 0.3},
{Pattern: "Magento_", Weight: 0.3},
}
}