Fix for XSS bug.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Mon, 2 Jan 2006 04:02:54 +0000 (04:02 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Mon, 2 Jan 2006 04:02:54 +0000 (04:02 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@1880 cb58f699-b61c-0410-a6fe-9272a202ed29

shib-target/shib-mlp.cpp

index 914d243..56434b9 100644 (file)
@@ -40,8 +40,28 @@ public:
   ShibMLPPriv();
   ~ShibMLPPriv() {}
   log4cpp::Category *log;
+
+  static void html_encode(string& os, const char* start);
 };  
 
+
+void ShibMLPPriv::html_encode(string& os, const char* start)
+{
+    while (start && *start) {
+        switch (*start) {
+            case '<':   os += "&lt;";       break;
+            case '>':   os += "&gt;";       break;
+            case '"':   os += "&quot;";     break;
+            case '\'':  os += "&rsquo;";    break;
+            case '(':   os += "&#40;";      break;
+            case ')':   os += "&#41;";      break;
+            case ':':   os += "&#58;";      break;
+            default:    os += *start;
+        }
+        start++;
+    }
+}
+
 ShibMLPPriv::ShibMLPPriv() : log(&(log4cpp::Category::getInstance("shibtarget.ShibMLP"))) {}
 
 static void trimspace (string& s)
@@ -99,7 +119,7 @@ const char* ShibMLP::run(const string& is, const IPropertySet* props, std::strin
 #ifdef HAVE_STRCASECMP
     if (!strncasecmp(thispos, "<shibmlp ", 9))
 #else
-    if (!strnicmp(thispos, "<shibmlp ", 9))
+    if (!_strnicmp(thispos, "<shibmlp ", 9))
 #endif
     {
         // Save this position off.
@@ -112,12 +132,12 @@ const char* ShibMLP::run(const string& is, const IPropertySet* props, std::strin
     
             map<string,string>::const_iterator i=m_map.find(key);
             if (i != m_map.end()) {
-                *output += i->second;
+                m_priv->html_encode(*output,i->second.c_str());
             }
             else {
                 pair<bool,const char*> p=props ? props->getString(key.c_str()) : pair<bool,const char*>(false,NULL);
                 if (p.first) {
-                    *output += p.second;
+                    m_priv->html_encode(*output,p.second);
                 }
                 else {
                     static const char* s1 = "<!-- Unknown SHIBMLP key: ";
@@ -132,7 +152,7 @@ const char* ShibMLP::run(const string& is, const IPropertySet* props, std::strin
 #ifdef HAVE_STRCASECMP
     else if (!strncasecmp(thispos, "<shibmlpif ", 11))
 #else
-    else if (!strnicmp(thispos, "<shibmlpif ", 11))
+    else if (!_strnicmp(thispos, "<shibmlpif ", 11))
 #endif
     {
         // Save this position off.
@@ -161,7 +181,7 @@ const char* ShibMLP::run(const string& is, const IPropertySet* props, std::strin
 #ifdef HAVE_STRCASECMP
                 if (!strncasecmp(thispos, "</shibmlpif>", 12))
 #else
-                if (!strnicmp(thispos, "</shibmlpif>", 12))
+                if (!_strnicmp(thispos, "</shibmlpif>", 12))
 #endif
                 {
                     // We found our terminator. Process the string in between.
@@ -182,7 +202,7 @@ const char* ShibMLP::run(const string& is, const IPropertySet* props, std::strin
 #ifdef HAVE_STRCASECMP
     else if (!strncasecmp(thispos, "<shibmlpifnot ", 14))
 #else
-    else if (!strnicmp(thispos, "<shibmlpifnot ", 14))
+    else if (!_strnicmp(thispos, "<shibmlpifnot ", 14))
 #endif
     {
         // Save this position off.
@@ -211,7 +231,7 @@ const char* ShibMLP::run(const string& is, const IPropertySet* props, std::strin
 #ifdef HAVE_STRCASECMP
                 if (!strncasecmp(thispos, "</shibmlpifnot>", 15))
 #else
-                if (!strnicmp(thispos, "</shibmlpifnot>", 15))
+                if (!_strnicmp(thispos, "</shibmlpifnot>", 15))
 #endif
                 {
                     // We found our terminator. Process the string in between.