nyx/tests/fixtures/xpath_injection/ruby/safe_xpath_query.rb
2026-05-07 01:29:31 -04:00

16 lines
443 B
Ruby

# Safe: user-supplied substring routed through the project-local
# `escape_xpath` helper before interpolation. The sanitizer clears
# XPATH_INJECTION so the sink does not fire.
require 'nokogiri'
def escape_xpath(raw)
raw.gsub("'", ''').gsub('"', '"')
end
def lookup(params)
doc = Nokogiri::XML(File.read("users.xml"))
user = params[:user]
safe = escape_xpath(user)
expr = "//user[name='#{safe}']"
doc.xpath(expr)
end