User input sanitization

Created on 21 May 2025, 10 days ago

Problem/Motivation

https://git.drupalcode.org/project/ai_seo_link_advisor/-/blob/1.0.x/src/...

used for example here without any sanitization: https://git.drupalcode.org/project/ai_seo_link_advisor/-/blob/1.0.4/src/...

Usage of a user input without sanitization or escape is not good practice from Drupal standards: https://www.drupal.org/docs/administering-a-drupal-site/security-in-drup...

Steps to reproduce

N/A

Proposed resolution

Sanitize the user input with one of the provided APIs:

  • Use t() and \Drupal::translation()->formatPlural() with @ or % placeholders to construct safe, translatable strings. See Code text translation API in Drupal 8 for more details.
  • Use Html::escape() for plain text.
  • Use Xss::filter() for text that should allow some HTML tags. Do not use it for HTML elements or attributes inside of a tag.
  • Use Xss::filterAdmin() for text entered by admin users that should allow most HTML.
  • Use UrlHelper::stripDangerousProtocols() or UrlHelper::filterBadProtocol() for checking URLs - the former can be used in conjunction with SafeMarkup::format().
  • Use Html::cleanCssIdentifier to filter and validly format a CSS identifier or other HTML attribute.

Remaining tasks

Add the sanitization to the input

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇹Italy bigbabert Milano, Italy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024