Markup returned by `generate` or `format` callbacks runs in the editor when inserted as an inline binding

Đang mở
#883 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php, wordpress
Lĩnh vực
backend, security

Hướng nghiên cứu

Start by reading InlineBindingButton.tsx and InlineBindings.php, then trace how generate and format callback values reach inline bindings. The issue outlines several possible sanitization points and their tradeoffs, so the right behavior needs project familiarity. Done means untrusted callback markup cannot execute in the editor while the documented behavior and front end remain consistent.

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

Mô tả

Description

Values of text typed fields are sanitized by the field type (Sanitizer::sanitize_primitive_type), but the output of a generate callback, a format callback, the remote_data_blocks_query_response_metadata filter and html typed fields is not. The editor inserts the value of an inline binding as markup (InlineBindingButton.tsx sets innerHTML), so markup such as <img src="x" onerror="..."> in such a value runs in the editor session when an editor inserts the field. Saved posts keep the markup only for users with unfiltered_html.

Reproduction: register a block whose output schema has a string field with a generate callback returning <img src="x" onerror="document.title='script-ran'">, insert the field as an inline binding in a paragraph, and check the editor canvas document title.

It needs custom code that returns untrusted markup in a text typed field. The built-in integrations do not. Trunk behaves this way today. The output schema docs now say that callback output is not sanitized by the field type.

Options

  • Filter the REST response with kses. Keeps formatting and matches the front end. Changes the response and the data saved in the post, depends on the site's allowed tags filter, alters text such as 1 < 2 and 3 > 2 unless only real tags are filtered, leaves fragments for malformed markup, and mangled values can trip the existing data-query entity decoding problem (every inline field of the record then falls back on the front end).
  • Escape the value at inline insert. Nothing can run. Formatting from custom callbacks shows as literal tags in the editor, and the inline field's saved text is escaped, so visitors would see literal tags if the live fetch fails.
  • Apply the declared field type's sanitizer to generate and format output. Cleanest rule, but a contract change for custom code that returns markup in text fields.
  • Sanitize in the editor (DOMPurify). Tried and dropped: it removed data-query from saved inline fields in some cases, changed rich text attributes for other blocks, and was bypassed by nested rich text.

Related

Values containing entity text such as &quot; make every inline field of that record fall back on the front end, because InlineBindings.php decodes entities once before json_decode. That is a separate problem that already happens on trunk and has its own fix.

Ngôn ngữ chính
PHP
Star
86
Fork
14
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
23

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 Automattic/remote-data-blocks

Tất cả issue của Automattic/remote-data-blocks

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.