Author: miguel
Date: 2007-01-11 19:56:10 -0500 (Thu, 11 Jan 2007)
New Revision: 70894
Modified:
trunk/mcs/class/System/System.Net/ChangeLog
trunk/mcs/class/System/System.Net/HttpListenerRequest.cs
trunk/mcs/class/System/Test/System.Net/ChangeLog
trunk/mcs/class/System/Test/System.Net/HttpListener2Test.cs
Log:
2007-01-11 Miguel de Icaza <[EMAIL PROTECTED]>
* HttpListener2Test.cs: Put a bunch of verbs that would not be
allowed.
2007-01-11 Miguel de Icaza <[EMAIL PROTECTED]>
* HttpListenerRequest.cs (SetRequestLine): Add validation for the
verbs.
Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2007-01-12 00:17:10 UTC (rev
70893)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2007-01-12 00:56:10 UTC (rev
70894)
@@ -1,6 +1,9 @@
2007-01-11 Miguel de Icaza <[EMAIL PROTECTED]>
- * HttpListenerRequest.cs: Allow any verbs to go through, not only
+ * HttpListenerRequest.cs (SetRequestLine): Add validation for the
+ verbs.
+
+ Allow any verbs to go through, not only
the white list of verbs.
Fixes: 80504
Modified: trunk/mcs/class/System/System.Net/HttpListenerRequest.cs
===================================================================
--- trunk/mcs/class/System/System.Net/HttpListenerRequest.cs 2007-01-12
00:17:10 UTC (rev 70893)
+++ trunk/mcs/class/System/System.Net/HttpListenerRequest.cs 2007-01-12
00:56:10 UTC (rev 70894)
@@ -81,6 +81,20 @@
}
method = parts [0];
+ foreach (char c in method){
+ int ic = (int) c;
+
+ if ((ic >= 'A' && ic <= 'Z') ||
+ (ic >= 'a' && ic <= 'z') ||
+ (ic > 32 && c < 127 && c != '(' && c != ')'
&& c != '<' &&
+ c != '<' && c != '>' && c != '@' && c !=
',' && c != ';' &&
+ c != ':' && c != '\\' && c != '"' && c !=
'/' && c != '[' &&
+ c != ']' && c != '?' && c != '=' && c !=
'{' && c != '}'))
+ continue;
+
+ context.ErrorMessage = "(Invalid verb)";
+ return;
+ }
#if false
//
Modified: trunk/mcs/class/System/Test/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Net/ChangeLog 2007-01-12 00:17:10 UTC
(rev 70893)
+++ trunk/mcs/class/System/Test/System.Net/ChangeLog 2007-01-12 00:56:10 UTC
(rev 70894)
@@ -1,3 +1,8 @@
+2007-01-11 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * HttpListener2Test.cs: Put a bunch of verbs that would not be
+ allowed.
+
2006-12-28 Gert Driesen <[EMAIL PROTECTED]>
* IPAddressTest.cs: Added 4-byte and null address tests.
Modified: trunk/mcs/class/System/Test/System.Net/HttpListener2Test.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Net/HttpListener2Test.cs 2007-01-12
00:17:10 UTC (rev 70893)
+++ trunk/mcs/class/System/Test/System.Net/HttpListener2Test.cs 2007-01-12
00:56:10 UTC (rev 70894)
@@ -128,13 +128,40 @@
[Test]
public void Test3 ()
{
- HttpListener listener = CreateAndStartListener
("http://127.0.0.1:9000/test3/");
- NetworkStream ns = CreateNS (9000);
- Send (ns, "MET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
// bad method
- string response = Receive (ns, 512);
- ns.Close ();
- listener.Close ();
- Assert.IsTrue (response.StartsWith ("HTTP/1.1 400"));
+ StringBuilder bad = new StringBuilder ();
+ for (int i = 0; i < 33; i++){
+ if (i != 13)
+ bad.Append ((char) i);
+ }
+ bad.Append ('(');
+ bad.Append (')');
+ bad.Append ('[');
+ bad.Append (']');
+ bad.Append ('<');
+ bad.Append ('>');
+ bad.Append ('@');
+ bad.Append (',');
+ bad.Append (';');
+ bad.Append (':');
+ bad.Append ('\\');
+ bad.Append ('"');
+ bad.Append ('/');
+ bad.Append ('?');
+ bad.Append ('=');
+ bad.Append ('{');
+ bad.Append ('}');
+
+ foreach (char b in bad.ToString ()){
+ HttpListener listener = CreateAndStartListener
("http://127.0.0.1:9000/test3/");
+ NetworkStream ns = CreateNS (9000);
+ Send (ns, String.Format ("MA{0} /
HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n", b)); // bad method
+
+ string response = Receive (ns, 512);
+ ns.Close ();
+ listener.Close ();
+ Console.WriteLine ("Response is: {0}",
response);
+ Assert.AreEqual (true, response.StartsWith
("HTTP/1.1 400"), String.Format ("Failed on {0}", (int) b));
+ }
}
[Test]
@@ -355,6 +382,21 @@
c.Response.Close ();
ns.Close ();
}
+
+ [Test]
+ public void Test17 ()
+ {
+ HttpListener listener = CreateAndStartListener
("http://127.0.0.1:9000/test17/");
+ NetworkStream ns = CreateNS (9000);
+ Send (ns, "RANDOM /test17/ HTTP/1.1\r\nHost:
127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
+ HttpListenerContext ctx = listener.GetContext ();
+ Send (ctx.Response.OutputStream, "%%%OK%%%");
+ string response = Receive (ns, 1024);
+ ns.Close ();
+ listener.Close ();
+ Assert.IsTrue (response.StartsWith ("HTTP/1.1 200"));
+ Assert.IsTrue (-1 != response.IndexOf
("Transfer-Encoding: chunked"));
+ }
}
[TestFixture]
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches