Unsanitized input in XML External Entity
- Rule ID: ruby_lang_xml_external_entity_vulnerability
- Languages: ruby
- Source: xml_external_entity_vulnerability.yml
Description
Avoid parsing untrusted data as XML. Such data could include URIs that resolve to resources that are outside of the current context, leading to XML External Entity (XXE) injection.
Remediations
- Do disable external entity expansion in REXML before parsing any XML from untrusted sources. Set the REXML::Security.entity_expansion_text_limit to 0.
REXML::Security.entity_expansion_text_limit = 0 # prevent REXML from expanding any text entities
def parse_xml(raw_xml)
begin
return REXML::Document.new(raw_xml)
rescue REXML::ParseException => e
# handle error
end
end - Do not allow REXML to expand text entities from untrusted input. This is the primary mechanism attackers use to perform XXE attacks. Avoid parsing XML without first disabling entity expansion.
def unsafe_parse_xml(raw_xml)
return REXML::Document.new(raw_xml) # unsafe
end
References
Associated CWE
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=ruby_lang_xml_external_entity_vulnerability
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=ruby_lang_xml_external_entity_vulnerability