To prevent potential data exfiltration or remote command execution via XML input.
defmodule VulnerableApp do
def parse(xml) do
xml
|> SweetXml.parse()
|> SweetXml.xpath(~x/data)
end
end
This code accepts and parses XML input using the SweetXml library without validating or sanitizing the input. As a result, an attacker could inject malicious XML data.
defmodule SecureApp do
def parse(xml) do
xml
|> sanitize_input()
|> SweetXml.parse()
|> SweetXml.xpath(~x/data)
end
defp sanitize_input(xml) do
# Add your sanitization logic here
end
end
This code properly sanitizes the XML input before parsing it and is configured to reject DTDs, mitigating the risk of XML injection attacks.