|
@@ -34,6 +34,8 @@ using System.Collections;
|
|
|
using System.Collections.Specialized;
|
|
using System.Collections.Specialized;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
+using System.Security;
|
|
|
|
|
+using System.Security.Permissions;
|
|
|
using System.Web.Configuration;
|
|
using System.Web.Configuration;
|
|
|
using System.Web.UI;
|
|
using System.Web.UI;
|
|
|
using System.Web.Util;
|
|
using System.Web.Util;
|
|
@@ -41,6 +43,8 @@ using System.Globalization;
|
|
|
|
|
|
|
|
namespace System.Web {
|
|
namespace System.Web {
|
|
|
|
|
|
|
|
|
|
+ // CAS - no InheritanceDemand here as the class is sealed
|
|
|
|
|
+ [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
|
|
|
public sealed class HttpRequest {
|
|
public sealed class HttpRequest {
|
|
|
HttpWorkerRequest worker_request;
|
|
HttpWorkerRequest worker_request;
|
|
|
HttpContext context;
|
|
HttpContext context;
|
|
@@ -219,7 +223,7 @@ namespace System.Web {
|
|
|
get {
|
|
get {
|
|
|
if (content_length == -1){
|
|
if (content_length == -1){
|
|
|
if (worker_request == null)
|
|
if (worker_request == null)
|
|
|
- throw new HttpException ("No HttpWorkerRequest");
|
|
|
|
|
|
|
+ return 0;
|
|
|
|
|
|
|
|
string cl = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderContentLength);
|
|
string cl = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderContentLength);
|
|
|
|
|
|
|
@@ -241,12 +245,11 @@ namespace System.Web {
|
|
|
public string ContentType {
|
|
public string ContentType {
|
|
|
get {
|
|
get {
|
|
|
if (content_type == null){
|
|
if (content_type == null){
|
|
|
- if (worker_request == null)
|
|
|
|
|
- throw new HttpException ("No HttpWorkerRequest");
|
|
|
|
|
|
|
+ if (worker_request != null)
|
|
|
|
|
+ content_type = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderContentType);
|
|
|
|
|
|
|
|
- content_type = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderContentType);
|
|
|
|
|
if (content_type == null)
|
|
if (content_type == null)
|
|
|
- content_type = "";
|
|
|
|
|
|
|
+ content_type = String.Empty;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return content_type;
|
|
return content_type;
|
|
@@ -259,9 +262,13 @@ namespace System.Web {
|
|
|
|
|
|
|
|
public HttpCookieCollection Cookies {
|
|
public HttpCookieCollection Cookies {
|
|
|
get {
|
|
get {
|
|
|
- if (cookies == null){
|
|
|
|
|
- string cookie_hv = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderCookie);
|
|
|
|
|
- cookies = new HttpCookieCollection (cookie_hv);
|
|
|
|
|
|
|
+ if (cookies == null) {
|
|
|
|
|
+ if (worker_request == null) {
|
|
|
|
|
+ cookies = new HttpCookieCollection ();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ string cookie_hv = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderCookie);
|
|
|
|
|
+ cookies = new HttpCookieCollection (cookie_hv);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (validate_cookies && !checked_cookies){
|
|
if (validate_cookies && !checked_cookies){
|
|
@@ -286,7 +293,7 @@ namespace System.Web {
|
|
|
public string FilePath {
|
|
public string FilePath {
|
|
|
get {
|
|
get {
|
|
|
if (worker_request == null)
|
|
if (worker_request == null)
|
|
|
- return null;
|
|
|
|
|
|
|
+ return "/"; // required for 2.0
|
|
|
|
|
|
|
|
if (file_path == null)
|
|
if (file_path == null)
|
|
|
file_path = UrlUtils.Canonic (worker_request.GetFilePath ());
|
|
file_path = UrlUtils.Canonic (worker_request.GetFilePath ());
|
|
@@ -311,7 +318,7 @@ namespace System.Web {
|
|
|
get {
|
|
get {
|
|
|
if (files == null) {
|
|
if (files == null) {
|
|
|
files = new HttpFileCollection ();
|
|
files = new HttpFileCollection ();
|
|
|
- if (IsContentType ("multipart/form-data", true)) {
|
|
|
|
|
|
|
+ if ((worker_request != null) && IsContentType ("multipart/form-data", true)) {
|
|
|
form = new WebROCollection ();
|
|
form = new WebROCollection ();
|
|
|
LoadMultiPart ();
|
|
LoadMultiPart ();
|
|
|
form.Protect ();
|
|
form.Protect ();
|
|
@@ -321,6 +328,7 @@ namespace System.Web {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ [MonoTODO]
|
|
|
public Stream Filter {
|
|
public Stream Filter {
|
|
|
get {
|
|
get {
|
|
|
throw new NotImplementedException ();
|
|
throw new NotImplementedException ();
|
|
@@ -458,11 +466,12 @@ namespace System.Web {
|
|
|
public NameValueCollection Headers {
|
|
public NameValueCollection Headers {
|
|
|
get {
|
|
get {
|
|
|
if (headers == null){
|
|
if (headers == null){
|
|
|
- if (worker_request == null)
|
|
|
|
|
- throw new HttpException ("No HttpWorkerRequest");
|
|
|
|
|
-
|
|
|
|
|
headers = new WebROCollection ();
|
|
headers = new WebROCollection ();
|
|
|
-
|
|
|
|
|
|
|
+ if (worker_request == null) {
|
|
|
|
|
+ headers.Protect ();
|
|
|
|
|
+ return headers;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (int i = 0; i < HttpWorkerRequest.RequestHeaderMaximum; i++){
|
|
for (int i = 0; i < HttpWorkerRequest.RequestHeaderMaximum; i++){
|
|
|
string hval = worker_request.GetKnownRequestHeader (i);
|
|
string hval = worker_request.GetKnownRequestHeader (i);
|
|
|
|
|
|
|
@@ -493,6 +502,8 @@ namespace System.Web {
|
|
|
if (http_method == null){
|
|
if (http_method == null){
|
|
|
if (worker_request != null)
|
|
if (worker_request != null)
|
|
|
http_method = worker_request.GetHttpVerbName ();
|
|
http_method = worker_request.GetHttpVerbName ();
|
|
|
|
|
+ else
|
|
|
|
|
+ http_method = "GET";
|
|
|
}
|
|
}
|
|
|
return http_method;
|
|
return http_method;
|
|
|
}
|
|
}
|
|
@@ -557,8 +568,10 @@ namespace System.Web {
|
|
|
|
|
|
|
|
void MakeInputStream ()
|
|
void MakeInputStream ()
|
|
|
{
|
|
{
|
|
|
- if (worker_request == null)
|
|
|
|
|
- throw new HttpException ("No HttpWorkerRequest");
|
|
|
|
|
|
|
+ if (worker_request == null) {
|
|
|
|
|
+ input_stream = new MemoryStream (new byte [0], 0, 0, false, true);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
//
|
|
//
|
|
|
// Use an unmanaged memory block as this might be a large
|
|
// Use an unmanaged memory block as this might be a large
|
|
@@ -655,11 +668,14 @@ namespace System.Web {
|
|
|
|
|
|
|
|
public bool IsSecureConnection {
|
|
public bool IsSecureConnection {
|
|
|
get {
|
|
get {
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return false;
|
|
|
return worker_request.IsSecure ();
|
|
return worker_request.IsSecure ();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string this [string key] {
|
|
public string this [string key] {
|
|
|
|
|
+ [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Low)]
|
|
|
get {
|
|
get {
|
|
|
// "The QueryString, Form, Cookies, or ServerVariables collection member
|
|
// "The QueryString, Form, Cookies, or ServerVariables collection member
|
|
|
// specified in the key parameter."
|
|
// specified in the key parameter."
|
|
@@ -679,6 +695,7 @@ namespace System.Web {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public NameValueCollection Params {
|
|
public NameValueCollection Params {
|
|
|
|
|
+ [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Low)]
|
|
|
get {
|
|
get {
|
|
|
if (all_params == null) {
|
|
if (all_params == null) {
|
|
|
all_params = new WebROCollection ();
|
|
all_params = new WebROCollection ();
|
|
@@ -713,7 +730,7 @@ namespace System.Web {
|
|
|
get {
|
|
get {
|
|
|
if (path_info == null) {
|
|
if (path_info == null) {
|
|
|
if (worker_request == null)
|
|
if (worker_request == null)
|
|
|
- return null;
|
|
|
|
|
|
|
+ return String.Empty;
|
|
|
path_info = worker_request.GetPathInfo ();
|
|
path_info = worker_request.GetPathInfo ();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -724,16 +741,27 @@ namespace System.Web {
|
|
|
public string PhysicalApplicationPath {
|
|
public string PhysicalApplicationPath {
|
|
|
get {
|
|
get {
|
|
|
if (worker_request == null)
|
|
if (worker_request == null)
|
|
|
- throw new NullReferenceException ();
|
|
|
|
|
-
|
|
|
|
|
- return HttpRuntime.AppDomainAppPath;
|
|
|
|
|
|
|
+ throw new ArgumentNullException (); // like 2.0, 1.x throws TypeInitializationException
|
|
|
|
|
+
|
|
|
|
|
+ string path = HttpRuntime.AppDomainAppPath;
|
|
|
|
|
+ if (SecurityManager.SecurityEnabled) {
|
|
|
|
|
+ new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
|
|
|
|
|
+ }
|
|
|
|
|
+ return path;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string PhysicalPath {
|
|
public string PhysicalPath {
|
|
|
get {
|
|
get {
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return String.Empty; // don't check security with an empty string!
|
|
|
|
|
+
|
|
|
if (physical_path == null)
|
|
if (physical_path == null)
|
|
|
physical_path = MapPath (CurrentExecutionFilePath);
|
|
physical_path = MapPath (CurrentExecutionFilePath);
|
|
|
|
|
+
|
|
|
|
|
+ if (SecurityManager.SecurityEnabled) {
|
|
|
|
|
+ new FileIOPermission (FileIOPermissionAccess.PathDiscovery, physical_path).Demand ();
|
|
|
|
|
+ }
|
|
|
return physical_path;
|
|
return physical_path;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -811,6 +839,8 @@ namespace System.Web {
|
|
|
if (worker_request != null) {
|
|
if (worker_request != null) {
|
|
|
request_type = worker_request.GetHttpVerbName ();
|
|
request_type = worker_request.GetHttpVerbName ();
|
|
|
http_method = request_type;
|
|
http_method = request_type;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ request_type = "GET";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return request_type;
|
|
return request_type;
|
|
@@ -822,6 +852,7 @@ namespace System.Web {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public NameValueCollection ServerVariables {
|
|
public NameValueCollection ServerVariables {
|
|
|
|
|
+ [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Low)]
|
|
|
get {
|
|
get {
|
|
|
if (server_variables == null)
|
|
if (server_variables == null)
|
|
|
server_variables = new ServerVariablesCollection (this);
|
|
server_variables = new ServerVariablesCollection (this);
|
|
@@ -848,27 +879,40 @@ namespace System.Web {
|
|
|
|
|
|
|
|
public Uri UrlReferrer {
|
|
public Uri UrlReferrer {
|
|
|
get {
|
|
get {
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
string hr = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderReferer);
|
|
string hr = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderReferer);
|
|
|
if (hr == null)
|
|
if (hr == null)
|
|
|
return null;
|
|
return null;
|
|
|
|
|
+
|
|
|
return new Uri (hr);
|
|
return new Uri (hr);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string UserAgent {
|
|
public string UserAgent {
|
|
|
get {
|
|
get {
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
return worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderUserAgent);
|
|
return worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderUserAgent);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string UserHostAddress {
|
|
public string UserHostAddress {
|
|
|
get {
|
|
get {
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
return worker_request.GetRemoteAddress ();
|
|
return worker_request.GetRemoteAddress ();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string UserHostName {
|
|
public string UserHostName {
|
|
|
get {
|
|
get {
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
return worker_request.GetRemoteName ();
|
|
return worker_request.GetRemoteName ();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -887,8 +931,8 @@ namespace System.Web {
|
|
|
|
|
|
|
|
public byte [] BinaryRead (int count)
|
|
public byte [] BinaryRead (int count)
|
|
|
{
|
|
{
|
|
|
- if (count <= 0)
|
|
|
|
|
- throw new ArgumentException ("count is <= 0");
|
|
|
|
|
|
|
+ if (count < 0)
|
|
|
|
|
+ throw new ArgumentException ("count is < 0");
|
|
|
|
|
|
|
|
Stream s = InputStream;
|
|
Stream s = InputStream;
|
|
|
byte [] ret = new byte [count];
|
|
byte [] ret = new byte [count];
|
|
@@ -932,6 +976,9 @@ namespace System.Web {
|
|
|
|
|
|
|
|
public string MapPath (string virtualPath)
|
|
public string MapPath (string virtualPath)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (worker_request == null)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
return MapPath (virtualPath, BaseVirtualDir, true);
|
|
return MapPath (virtualPath, BaseVirtualDir, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -974,9 +1021,13 @@ namespace System.Web {
|
|
|
Stream output = new FileStream (filename, FileMode.Create);
|
|
Stream output = new FileStream (filename, FileMode.Create);
|
|
|
if (includeHeaders) {
|
|
if (includeHeaders) {
|
|
|
StringBuilder sb = new StringBuilder ();
|
|
StringBuilder sb = new StringBuilder ();
|
|
|
- string version = worker_request.GetHttpVersion ();
|
|
|
|
|
- InitUriBuilder ();
|
|
|
|
|
- string path = uri_builder.Path;
|
|
|
|
|
|
|
+ string version = String.Empty;
|
|
|
|
|
+ string path = "/";
|
|
|
|
|
+ if (worker_request != null) {
|
|
|
|
|
+ version = worker_request.GetHttpVersion ();
|
|
|
|
|
+ InitUriBuilder ();
|
|
|
|
|
+ path = uri_builder.Path;
|
|
|
|
|
+ }
|
|
|
string qs = null;
|
|
string qs = null;
|
|
|
if (query_string != null && query_string != "")
|
|
if (query_string != null && query_string != "")
|
|
|
qs = "?" + query_string;
|
|
qs = "?" + query_string;
|