diff --git a/nselib/omp2.lua b/nselib/omp2.lua index 83c38cdd2..d96d51a86 100644 --- a/nselib/omp2.lua +++ b/nselib/omp2.lua @@ -39,6 +39,18 @@ if pcall(require,'openssl') then HAVE_SSL = true end +--- Escapes XML special characters in a string so it can be safely +-- embedded in XML element content. +-- @param s the string to escape +-- @return the escaped string +local function xml_escape(s) + return (s:gsub("&", "&") + :gsub("<", "<") + :gsub(">", ">") + :gsub('"', """) + :gsub("'", "'")) +end + --- A Session class holds connection and interaction with the server Session = { @@ -74,10 +86,9 @@ Session = { authenticate = function(self, username, password) local status, err, xmldata - -- TODO escape credentials status, err = self.socket:send("" - .. "" .. username .. "" - .. "" .. password .. "" + .. "" .. xml_escape(username) .. "" + .. "" .. xml_escape(password) .. "" .. "") if not status then