diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/ConstrainedDataObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/ConstrainedDataObject.cs
deleted file mode 100644
index 2de31018e34..00000000000
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/ConstrainedDataObject.cs
+++ /dev/null
@@ -1,282 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-//
-//
-//
-// Description: Internal class implemented to primarily disable the XAML cut and paste of content from a
-// partial trust source to a full trust target
-//
-// See spec at Rich%20Clipboard%20in%20Sandbox%20Spec.doc
-//
-//
-
-namespace MS.Internal
-{
- using System;
- using System.Collections.Generic;
- using System.Security;
- using System.Security.Permissions;
- using System.Windows;
-
- // PreSharp uses message numbers that the C# compiler doesn't know about.
- // Disable the C# complaints, per the PreSharp documentation.
-#pragma warning disable 1634, 1691
- #region ConstrainedDataObject Class
- ///
- /// Implements a wrapper class the helps prevent the copy paste of xaml content from partial trust to full trust
- /// This class is instantiated and returned in the case of copy from a partial trust source to a full trust or >partial trust
- /// target. The core functionality here is to strip and deny any requests for XAML content or ApplicationTrust Content in a DataObject
- /// Please note it is by intent that we create a blocked list versus an allowed list of allowed types so as to not block of scenarios like
- /// inking from getting their content in a full trust application if they want to.
- ///
- internal sealed class ConstrainedDataObject : System.Windows.IDataObject
- {
- //------------------------------------------------------
- //
- // Constructors
- //
- //------------------------------------------------------
-
- #region Constructors
-
-
- ///
- /// Initializes a new instance of the class, containing the specified data.
- ///
- internal ConstrainedDataObject(System.Windows.IDataObject data)
- {
- // This check guarantees us that we can never create a Constrained data Object with a null dataobject
- Invariant.Assert(data != null);
- _innerData = data;
- }
-
- #endregion Constructors
-
- //------------------------------------------------------
- //
- // Public Methods
- //
- //------------------------------------------------------
-
- #region Public Methods
-
- ///
- /// Retrieves the data associated with the specified data
- /// format, using an automated conversion parameter to determine whether to convert
- /// the data to the format.
- ///
- public object GetData(string format, bool autoConvert)
- {
- if (format == null)
- {
- throw new ArgumentNullException("format");
- }
- if (IsCriticalFormat(format))
- {
- return null;
- }
- return _innerData.GetData(format, autoConvert);
- }
-
- ///
- /// Retrieves the data associated with the specified data
- /// format.
- ///
- public object GetData(string format)
- {
- if (format == null)
- {
- throw new ArgumentNullException("format");
- }
- return GetData(format, true);
- }
-
- ///
- /// Retrieves the data associated with the specified class
- /// type format.
- ///
- public object GetData(Type format)
- {
- if (format == null)
- {
- throw new ArgumentNullException("format");
- }
- return GetData(format.FullName);
- }
-
- ///
- /// Determines whether data stored in this instance is
- /// associated with, or can be converted to, the specified
- /// format.
- ///
- public bool GetDataPresent(Type format)
- {
- if (format == null)
- {
- throw new ArgumentNullException("format");
- }
- return (GetDataPresent(format.FullName));
- }
-
- ///
- /// Determines whether data stored in this instance is
- /// associated with the specified format, using an automatic conversion
- /// parameter to determine whether to convert the data to the format.
- ///
- public bool GetDataPresent(string format, bool autoConvert)
- {
- bool dataPresent = false;
-
- if (format == null)
- {
- throw new ArgumentNullException("format");
- }
- if (!IsCriticalFormat(format))
- {
- dataPresent = _innerData.GetDataPresent(format, autoConvert);
- }
- return dataPresent;
- }
-
- ///
- /// Determines whether data stored in this instance is
- /// associated with, or can be converted to, the specified
- /// format.
- ///
- public bool GetDataPresent(string format)
- {
- if (format == null)
- {
- throw new ArgumentNullException("format");
- }
- return GetDataPresent(format, true);;
- }
-
- ///
- /// Gets a list of all formats that data stored in this
- /// instance is associated with or can be converted to, using an automatic
- /// conversion parameter to
- /// determine whether to retrieve all formats that the data can be converted to or
- /// only native data formats.
- ///
- public string[] GetFormats(bool autoConvert)
- {
- string[] formats = _innerData.GetFormats(autoConvert);
- if (formats != null)
- {
- StripCriticalFormats(formats);
- }
- return formats;
-}
-
- ///
- /// Gets a list of all formats that data stored in this instance is associated
- /// with or can be converted to.
- ///
- public string[] GetFormats()
- {
- return GetFormats(true);
- }
-
- ///
- /// Stores the specified data in
- /// this instance, using the class of the data for the format.
- ///
- public void SetData(object data)
- {
- _innerData.SetData(data);
- }
-
- ///
- /// Stores the specified data and its associated format in this
- /// instance.
- ///
- public void SetData(string format, object data)
- {
- _innerData.SetData(format, data);
- }
-
- ///
- /// Stores the specified data and
- /// its associated class type in this instance.
- ///
- public void SetData(Type format, object data)
- {
- _innerData.SetData(format, data);
- }
-
- ///
- /// Stores the specified data and its associated format in
- /// this instance, using the automatic conversion parameter
- /// to specify whether the
- /// data can be converted to another format.
- ///
- public void SetData(string format, Object data, bool autoConvert)
- {
- _innerData.SetData(format, data, autoConvert);
- }
-
-
-
- #endregion Public Methods
-
- //------------------------------------------------------
- //
- // Internal Methods
- //
- //------------------------------------------------------
-
- #region Internal Methods
-
- ///
- /// Return true if the format string are equal(Case-senstive).
- ///
- private static bool IsFormatEqual(string format1, string format2)
- {
- return (String.CompareOrdinal(format1, format2) == 0);
- }
-
-
- ///
- /// This code looks for Xaml and ApplicationTrust strings in an array of strings and removed them. The reason for that is
- /// that since the only scenario this class is used in is when the target application has more permissions than the source then
- /// we want to ensure that the target application cannot get to xaml and application trust formats if they come out of a partial trust source.
- ///
- private string[] StripCriticalFormats(string[] formats)
- {
- List resultList = new List();
- for (uint currentFormat = 0; currentFormat < formats.Length; currentFormat++)
- {
- if (!IsCriticalFormat(formats[currentFormat]))
- {
- resultList.Add(formats[currentFormat]);
- }
- }
- return resultList.ToArray();
- }
-
- ///
- private bool IsCriticalFormat(string format)
- {
- return (IsFormatEqual(format, DataFormats.Xaml) ||
- IsFormatEqual(format, DataFormats.ApplicationTrust));
- }
- #endregion Private Methods
-
- //------------------------------------------------------
- //
- // Private Fields
- //
- //------------------------------------------------------
-
- #region Private Fields
- // Inner data object of IDataObject.
- private System.Windows.IDataObject _innerData;
- #endregion Private Fields
-
-
- }
- #endregion ConstrainedDataObject Class
-}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
index ee08a7b5f8d..add968bdedc 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
@@ -108,7 +108,6 @@
-
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs
index b5319b4450d..bac56863b94 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs
@@ -651,46 +651,6 @@ private static bool IsDynamicCodePolicyEnabled()
return isEnabled;
}
- private static bool IsDataObjectFromLessPriviligedApplicationDomain(IDataObject dataObjectToApply)
- {
- bool retVal = false;
- object applicationTrust = null;
- // Extract the permission set in case of xaml cut and paste
- // extract permission set if it exists if not data came from full trust app and we do not care
- bool isApplicationTrustFormatPresent = false;
- isApplicationTrustFormatPresent = dataObjectToApply.GetDataPresent(DataFormats.ApplicationTrust, /*autoConvert:*/false);
- if (isApplicationTrustFormatPresent)
- {
- applicationTrust = dataObjectToApply.GetData(DataFormats.ApplicationTrust, /*autoConvert:*/false);
- }
-
- if (applicationTrust != null)
- {
- string applicationTrustText = null;
- // convert to string
- applicationTrustText = applicationTrust.ToString();
-
-
- // Convert string to permission set for getting permission set of source
- PermissionSet permissionSetSource;
- try
- {
- SecurityElement securityElement = SecurityElement.FromString(applicationTrustText);
- permissionSetSource = new System.Security.PermissionSet(PermissionState.None);
- permissionSetSource.FromXml(securityElement);
- }
- catch(XmlSyntaxException)
- {
- // This is the condition where we have Malformed XML in the clipboard for application trust
- // here we will fail silently since we do not want to break arbitrary applications
- // but since we cannot establish the validity of the application trust content we will fall back to
- // whatever is more secure
- return true;
- }
- }
- return retVal;
- }
-
private static IDataObject GetDataObjectInternal()
{
IDataObject dataObject;
@@ -734,23 +694,7 @@ private static IDataObject GetDataObjectInternal()
{
dataObject = null;
}
- // We make this check outside of the loop independant of whether the data is ole data object or IDataObject
- // Although one is unable to create an OleDataObject in partial trust we still need to ensure that if he did
- // we strip the formats we care about by wrapping in ConstrainedDataObject
- if (dataObject != null)
- {
- // this is the case we are concerend about where content comes from partial trust into full trust
- // in the case where data contained is in one of the two formats: XAML or ApplicationTrust we return a wrapper
- // that blocks access to these
- if (IsDataObjectFromLessPriviligedApplicationDomain(dataObject) &&
- (dataObject.GetDataPresent(DataFormats.Xaml, /*autoConvert:*/false) ||
- dataObject.GetDataPresent(DataFormats.ApplicationTrust, /*autoConvert:*/false)))
- {
- // in this case we set the data object to be a wrapper data object that blocks off
- // xaml or application trust formats if they exist
- dataObject = new ConstrainedDataObject(dataObject);
- }
- }
+
return dataObject;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs
index f6f4bc59dd8..237dab75f2c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs
@@ -396,6 +396,7 @@ public void SetData(Type format, object data)
///
/// Callers must have UIPermission(UIPermissionClipboard.AllClipboard) to call this API.
///
+ [FriendAccessAllowed]
public void SetData(string format, Object data, bool autoConvert)
{
if (format == null)
@@ -408,7 +409,7 @@ public void SetData(string format, Object data, bool autoConvert)
throw new ArgumentException(SR.Get(SRID.DataObject_EmptyFormatNotAllowed));
}
- CriticalSetData(format, data, autoConvert);
+ _innerData.SetData(format, data, autoConvert);
}
@@ -1326,18 +1327,6 @@ internal static string[] GetMappedFormats(string format)
#region Private Methods
- ///
- ///
- ///
- [FriendAccessAllowed]
- internal void CriticalSetData(string format, Object data, bool autoConvert)
- {
- if (data == null)
- {
- throw new ArgumentNullException("data");
- }
- _innerData.SetData(format, data, autoConvert);
- }
///
/// Behaves like IComDataObject.GetData and IComDataObject.GetDataHere,
@@ -2164,28 +2153,12 @@ private static bool IsDataSystemBitmapSource(object data)
private static bool IsFormatAndDataSerializable(string format, object data)
{
return
- (IsFormatNotSupportedInPartialTrust(format))
- &&
- (IsFormatEqual(format, DataFormats.Serializable)
+ IsFormatEqual(format, DataFormats.Serializable)
|| data is ISerializable
- || (data != null && data.GetType().IsSerializable));
+ || (data != null && data.GetType().IsSerializable);
}
- ///
- /// This code is used to determine whether any of the formats in the list here are supported in partial trust.
- /// By adding an entry here we are letting consumers set and get data for this format in partial trust.
- ///
- ///
- ///
- private static bool IsFormatNotSupportedInPartialTrust(string format)
- {
- return (!IsFormatEqual(format, DataFormats.Text)
- && !IsFormatEqual(format, DataFormats.OemText)
- && !IsFormatEqual(format, DataFormats.UnicodeText)
- && !IsFormatEqual(format, DataFormats.CommaSeparatedValue)
- && !IsFormatEqual(format, DataFormats.Xaml)
- && !IsFormatEqual(format, DataFormats.ApplicationTrust));
- }
+
///
/// Return true if the format string are equal(Case-senstive).
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/XamlClipboardData.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/XamlClipboardData.cs
index 351d463d9e0..773cad72f20 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/XamlClipboardData.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/XamlClipboardData.cs
@@ -98,16 +98,7 @@ protected override void DoCopy(IDataObject dataObject)
// Set the data object as XML format.
dataObject.SetData(DataFormats.Xaml, xmlData.ToString());
-
- //
- // we need to copy the permission set on the clipboard for
- // the Clipboard class methods. See security note for details.
- //
- PermissionSet permSet = SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin();
- string setString = permSet.ToString();
- Debug.Assert(setString.Length > 0);
- dataObject.SetData(DataFormats.ApplicationTrust, setString);
-}
+ }
// Retrieves the Xaml from the IDataObject and instantiate the elements based on the Xaml
protected override void DoPaste(IDataObject dataObject)
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs
index 8d731f0eab7..b95b2b70ffb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs
@@ -8334,7 +8334,7 @@ protected virtual void OnExecutedCopy(ExecutedRoutedEventArgs args)
foreach (string format in formats)
{
- dataObject.CriticalSetData(format, dataGridStringBuilders[format].ToString(), false /*autoConvert*/);
+ dataObject.SetData(format, dataGridStringBuilders[format].ToString(), false /*autoConvert*/);
}
Clipboard.CriticalSetDataObject(dataObject, true /* Copy */);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorCopyPaste.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorCopyPaste.cs
index 83f7cf1b5f7..c31c8371f65 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorCopyPaste.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorCopyPaste.cs
@@ -109,14 +109,14 @@ internal static DataObject _CreateDataObject(TextEditor This, bool isDragDrop)
// ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Text))
{
- CriticalSetDataWrapper(dataObject,DataFormats.Text, textString);
+ ((DataObject)dataObject).SetData(DataFormats.Text, textString, false);
}
// Copy unicode text into data object.
// ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.UnicodeText))
{
- CriticalSetDataWrapper(dataObject,DataFormats.UnicodeText, textString);
+ ((DataObject)dataObject).SetData(DataFormats.UnicodeText, textString, false);
}
}
@@ -173,15 +173,7 @@ internal static DataObject _CreateDataObject(TextEditor This, bool isDragDrop)
if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Xaml))
{
// Place Xaml data onto the dataobject using safe setter
- CriticalSetDataWrapper(dataObject, DataFormats.Xaml, xamlText);
-
- // The dataobject itself must hold an information about permission set
- // of the source appdomain. Set it there:
-
- // Package permission set for the current appdomain
- PermissionSet psCurrentAppDomain = SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin();
- string permissionSetCurrentAppDomain = psCurrentAppDomain.ToString();
- CriticalSetDataWrapper(dataObject, DataFormats.ApplicationTrust, permissionSetCurrentAppDomain);
+ ((DataObject)dataObject).SetData(DataFormats.Xaml, xamlText, false);
}
}
}
@@ -716,22 +708,6 @@ private static void OnPasteFormat(object sender, ExecutedRoutedEventArgs args)
// Provide an implementation for this command
}
- ///
- /// This code is used to call into an internal overload to set data which circumvents the demand for
- /// all clipboard permission. Although this is not the cleanest we prefer to cast it to DataObject
- /// and call the critical overload to reduce the scope of the code that gets called here.
- /// This saves us one high level assert.
- ///
- ///
- ///
- ///
- private static void CriticalSetDataWrapper(IDataObject dataObjectValue, string format, string content)
- {
- if (dataObjectValue is DataObject)
- {
- ((DataObject)dataObjectValue).CriticalSetData(format, content, format == DataFormats.ApplicationTrust ? /*autoConvert:*/false : true);
- }
- }
///
/// Paste the content data(Text, Unicode, Xaml and Rtf) to the current text selection
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs
index 4a523b17636..06c908f02a0 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs
@@ -119,12 +119,6 @@ internal static int MapUrlToZoneWrapper(Uri uri)
curSecMgr = null;
return targetZone;
}
-
- internal static PermissionSet ExtractAppDomainPermissionSetMinusSiteOfOrigin()
- {
- return new PermissionSet(PermissionState.Unrestricted);
- }
-
#endif