Skip to content

Commit d6bf90d

Browse files
authored
Fix CMS detection for Magento, PrestaShop and Webflow (#49)
1 parent 66bf8bd commit d6bf90d

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

internal/stack/stack.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,18 @@ func detectCMS(r *Result, h http.Header, html string) {
219219
return
220220
}
221221
// Magento
222-
if strings.Contains(html, "/static/frontend/magento/") || strings.Contains(html, "magento_") || strings.Contains(html, "mage/") {
222+
if strings.Contains(html, "/static/frontend/magento/") ||
223+
strings.Contains(html, "magento_") ||
224+
strings.Contains(html, "data-mage-init") ||
225+
strings.Contains(html, "x-magento-init") ||
226+
strings.Contains(html, "mage/cookies") {
223227
r.CMS = "Magento"
224228
return
225229
}
226230
// PrestaShop
227-
if strings.Contains(html, "prestashop") || strings.Contains(html, "/modules/ps_") {
231+
if strings.Contains(html, "/modules/ps_") ||
232+
strings.Contains(html, "var prestashop") ||
233+
strings.Contains(html, `id="prestashop"`) {
228234
r.CMS = "PrestaShop"
229235
return
230236
}
@@ -234,7 +240,10 @@ func detectCMS(r *Result, h http.Header, html string) {
234240
return
235241
}
236242
// Webflow
237-
if strings.Contains(html, "webflow.com") || strings.Contains(html, "wf-page") {
243+
if strings.Contains(html, "data-wf-page") ||
244+
strings.Contains(html, "data-wf-site") ||
245+
strings.Contains(html, "wf-page") ||
246+
strings.Contains(html, "website-files.com") {
238247
r.CMS = "Webflow"
239248
return
240249
}

internal/stack/stack_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stack
22

33
import (
4+
"net/http"
45
"slices"
56
"strings"
67
"testing"
@@ -99,6 +100,60 @@ func TestDetectWPPlugins(t *testing.T) {
99100
}
100101
}
101102

103+
func TestDetectCMS(t *testing.T) {
104+
tests := []struct {
105+
name string
106+
html string
107+
want string
108+
}{
109+
{
110+
name: "Magento from data-mage-init",
111+
html: `<div data-mage-init='{"someWidget":{}}'></div>`,
112+
want: "Magento",
113+
},
114+
{
115+
name: "Magento from static path",
116+
html: `<link href="/static/frontend/magento/luma/en_US/css/styles.css">`,
117+
want: "Magento",
118+
},
119+
{
120+
name: "Magento not detected from image MIME types",
121+
html: `<link rel="icon" type="image/png" href="/fav.png"><img src="data:image/svg+xml;base64,abc">`,
122+
want: "",
123+
},
124+
{
125+
name: "PrestaShop from module path",
126+
html: `<link href="/modules/ps_shoppingcart/css/cart.css">`,
127+
want: "PrestaShop",
128+
},
129+
{
130+
name: "PrestaShop not detected from prose mention",
131+
html: `<p>We migrated from prestashop last year.</p>`,
132+
want: "",
133+
},
134+
{
135+
name: "Webflow from data-wf-page",
136+
html: `<html data-wf-page="abc123" data-wf-site="def456">`,
137+
want: "Webflow",
138+
},
139+
{
140+
name: "Webflow not detected from a link to webflow.com",
141+
html: `<a href="https://webflow.com">Built with Webflow</a>`,
142+
want: "",
143+
},
144+
}
145+
146+
for _, tt := range tests {
147+
t.Run(tt.name, func(t *testing.T) {
148+
r := &Result{}
149+
detectCMS(r, http.Header{}, strings.ToLower(tt.html))
150+
if r.CMS != tt.want {
151+
t.Errorf("expected CMS %q, got %q", tt.want, r.CMS)
152+
}
153+
})
154+
}
155+
}
156+
102157
func TestDetectJSLibs(t *testing.T) {
103158
tests := []struct {
104159
name string

0 commit comments

Comments
 (0)