fix: social images are validated on the API, MCP, batch and import paths (WR-16)
Only the admin seoimage field refused values that are not a path or an http(s) URL; SetURLSEO, SaveRule and SaveSettings stored javascript:, data: or protocol-relative values, which /resolve then served as og:image. All three now refuse them with image.url_invalid.
This commit is contained in:
15
mcp_test.go
15
mcp_test.go
@@ -242,6 +242,21 @@ func TestManagementAPI(t *testing.T) {
|
||||
t.Fatalf("bad url = %d, want 422", rec.Code)
|
||||
}
|
||||
|
||||
// A social image is a path or an http(s) URL on every write path, as
|
||||
// in the admin field (WR-16).
|
||||
for _, bad := range []string{"javascript:alert(1)", "data:image/png;base64,AAAA", "//evil.example/x.png", "a b.png"} {
|
||||
if rec := env.mcp(t, http.MethodPut, "/_seo/api/v1/seo", agent, map[string]any{"url": "/pages/a", "values": map[string]any{"og_image": bad}}); rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), `"og_image"`) {
|
||||
t.Fatalf("set_url_seo og_image %q = %d %s, want 422 on og_image", bad, rec.Code, rec.Body.String())
|
||||
}
|
||||
if rec := env.mcp(t, http.MethodPost, "/_seo/api/v1/rules", agent, map[string]any{"url": "/img-rule", "og_image": bad}); rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), `"og_image"`) {
|
||||
t.Fatalf("create_rule og_image %q = %d %s, want 422 on og_image", bad, rec.Code, rec.Body.String())
|
||||
}
|
||||
if rec := env.mcp(t, http.MethodPut, "/_seo/api/v1/settings", agent, map[string]any{"default_og_image": bad}); rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), `"default_og_image"`) {
|
||||
t.Fatalf("update_settings default_og_image %q = %d %s, want 422", bad, rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
env.mcpExpect(t, http.StatusOK, http.MethodPut, "/_seo/api/v1/seo", agent, map[string]any{"url": "/pages/a", "values": map[string]any{"og_image": "https://cdn.example/a.png"}})
|
||||
|
||||
// URL rules.
|
||||
rule := env.mcpExpect(t, http.StatusCreated, http.MethodPost, "/_seo/api/v1/rules", agent, map[string]any{"url": "/blog?tag=*", "match": "pattern", "robots": "noindex"})
|
||||
data, _ := rule["data"].(map[string]any)
|
||||
|
||||
Reference in New Issue
Block a user