Este producto no es compatible con el sitio Datadog seleccionado. ().
Esta página aún no está disponible en español. Estamos trabajando en su traducción.
Si tienes alguna pregunta o comentario sobre nuestro actual proyecto de traducción, no dudes en ponerte en contacto con nosotros.

Metadata

ID: ruby-security/xxe-nokogiri

Language: Ruby

Severity: Warning

Category: Security

CWE: 611

Description

This rule addresses the prevention of XML External Entity (XXE) with the Nokogiri library.

To avoid XXE vulnerabilities, developers should disable the processing of external entities and external DTDs when parsing XML. In Ruby, when using the Nokogiri library, this can be achieved by configuring the parser with cfg.strict.nonet and removing any external subsets from the document.

A secure approach involves parsing XML with a block that sets these options, for example: doc = Nokogiri::XML(params[:xml]) do |cfg| cfg.strict.nonet end followed by doc.remove_external_subset. This ensures that external resources are not loaded or processed, mitigating the risk of XXE attacks. Adopting these practices helps maintain the confidentiality and integrity of your application’s data.

Non-Compliant Code Examples

doc = Nokogiri::XML(params[:xml]) # can fetch file:/// or http://…
val = doc.at("//token").text

Compliant Code Examples

doc = Nokogiri::XML(params[:xml]) do |cfg|
  cfg.strict.nonet
end
doc.remove_external_subset
doc.xpath("//token").text
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Integraciones sin problemas. Prueba Datadog Code Security