Domain mapping fix_srcset applies the request's mapped domain to other sites' images after switch_to_blog

Đang mở Phù hợp với người mới
#2,131 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php, wordpress
Lĩnh vực
backend

Hướng nghiên cứu

Lỗi nằm ở fix_srcset() trong inc/class-domain-mapping.php, được gắn vào wp_calculate_image_srcset, và thiếu bước kiểm tra blog ID mà mangle_url() đã thực hiện. So sánh hai phương thức, sau đó thêm một lệnh return sớm khi blog ID của current_mapping khác với get_current_blog_id(). Cũng kiểm tra các filter trong register_mapped_filters() xem có cùng lỗ hổng này không. Hoàn thành khi việc render ảnh của site khác bằng switch_to_blog() nhận được các URL srcset riêng, và ảnh trên site đã ánh xạ vẫn giữ domain đã ánh xạ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug origin:interactive status:available

Problem

Domain_Mapping::fix_srcset() (inc/class-domain-mapping.php, hooked on wp_calculate_image_srcset) rewrites every srcset URL with replace_url() using $this->current_mapping, the mapping of the request's host. Unlike mangle_url(), which returns early when $current_mapping->get_blog_id() !== get_current_blog_id(), fix_srcset() has no site check.

So when a request for mapped site A calls switch_to_blog(B) and renders B's images, B's srcset URLs get A's domain (https://site-a.example/app/uploads/sites/B/...), while src stays correct. On a production network (2026-11-21) this was cached in Elementor's _elementor_element_cache for four posts of one site. A CDN page-URL rewriter then replaced only the upload path, leaving A's host in front of the CDN URL (https://site-a.examplehttps://cdn.example/...), so the logo, banners and product images failed to load on every page of site B.

Fix

In fix_srcset(), return $sources unchanged unless $this->current_mapping->get_blog_id() === get_current_blog_id(), matching mangle_url(). Optionally, use the mapping for the current blog instead of returning early. Check the other filters registered in register_mapped_filters() for the same missing guard.

Files Scope
  • EDIT: inc/class-domain-mapping.php (fix_srcset(), around line 705)

Verification

  • On a multisite with a mapped domain for site A, request A's front end with code that runs switch_to_blog(B); echo wp_get_attachment_image($id_on_B, 'full'); restore_current_blog();. Before the fix, srcset URLs use A's domain; after it, they use B's own URLs.
  • Regression: images rendered on A itself still get A's mapped domain in srcset.

aidevops.sh v3.39.189 plugin for OpenCode

Ngôn ngữ chính
PHP
Star
219
Fork
88
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
58

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Ultimate-Multisite/ultimate-multisite

Tất cả issue của Ultimate-Multisite/ultimate-multisite

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.