Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

WordPress plugin 1.0.0: proxy drops Content-Type (all events rejected) and inline SDK is always rejected

Đang mở Phù hợp với người mới
#610 1 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
73/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
api, backend

Hướng nghiên cứu

Bắt đầu với openpanel.php, tập trung vào collect_request_headers(), proxy_request() và is_valid_javascript_content(). Theo dõi cách các header của request và việc xác thực SDK inline ảnh hưởng đến việc chuyển tiếp sự kiện, sau đó kiểm tra cách xử lý phản hồi của proxy. Công việc được xem là hoàn tất khi proxy chuyển tiếp Content-Type, chấp nhận tập lệnh SDK được mô tả và trả về phản hồi upstream dưới dạng đối tượng JSON; issue không nêu bài kiểm thử nào cần chạy.

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

Mô tả

The WordPress plugin (v1.0.0) doesn't track anything on our site, because of two bugs in openpanel.php.

1. Proxy drops the Content-Type header, so every event is rejected

collect_request_headers() only forwards $_SERVER keys starting with HTTP_. PHP stores the Content-Type under CONTENT_TYPE, without that prefix, so the proxy never forwards it. The API then rejects every event:

POST /wp-json/openpanel/track → 400 {"status":400,"error":"Error","message":"body/type Invalid input"}

The same request sent directly to api.openpanel.dev/track returns 200.

Fix in proxy_request():

$content_type = $request->get_header('content_type');
if ($content_type) {
    $incoming['Content-Type'] = $content_type;
}

2. The inline op1.js always fails validation, so the plugin falls back to the CDN script, which ad blockers block

is_valid_javascript_content() rejects any script that matches /on\w+\s*=/i. op1.js contains r.onload=, r.onerror= and this.options=, so the inlined SDK is rejected on every page load. The plugin then loads https://openpanel.dev/op1.js, which Safari and ad blockers block, which defeats the purpose of the proxy.

Fix: remove on\w+\s*= from the pattern. op1.js comes from your own HTTPS endpoint, so the check doesn't protect against anything.

if (preg_match('/(?:javascript:|data:|vbscript:)/i', $js_content)) {

With both changes, events arrive correctly, including from browsers with tracker blocking.

Smaller issue: proxy_request() passes the raw upstream body string to WP_REST_Response, which JSON-encodes it again. The browser therefore receives "{\"deviceId\":...}", a JSON string rather than an object. Decoding it first (json_decode($bodyOut)) would fix that.

Disclaimer: I wrote this Issue Description with the help of AI

Ngôn ngữ chính
TypeScript
Star
7.2k
Fork
523
Merge trung bình
15 giờ 24 phút
Pull request đã merge (30 ngày)
41

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

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

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 Openpanel-dev/openpanel

Tất cả issue của Openpanel-dev/openpanel

Issue tương tự

Thêm issue về TypeScript

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.