Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix security transparency issue #80478

Merged
merged 3 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/libraries/Common/src/System/HexConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public static void ToBytesBuffer(byte value, Span<byte> buffer, int startingInde
buffer[startingIndex] = (byte)(packedResult >> 8);
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ToCharsBuffer(byte value, Span<char> buffer, int startingIndex = 0, Casing casing = Casing.Upper)
{
Expand Down Expand Up @@ -190,9 +187,6 @@ public static void EncodeToUtf16(ReadOnlySpan<byte> bytes, Span<char> chars, Cas
}
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public static unsafe string ToString(ReadOnlySpan<byte> bytes, Casing casing = Casing.Upper)
{
#if NETFRAMEWORK || NETSTANDARD2_0
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ System.Diagnostics.DiagnosticSource</PackageDescription>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<DefineConstants Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">$(DefineConstants);ALLOW_PARTIALLY_TRUSTED_CALLERS;ENABLE_HTTP_HANDLER</DefineConstants>
<DefineConstants Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">$(DefineConstants);ENABLE_HTTP_HANDLER</DefineConstants>
<DefineConstants Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">$(DefineConstants);W3C_DEFAULT_ID_FORMAT;MEMORYMARSHAL_SUPPORT;OS_ISBROWSER_SUPPORT</DefineConstants>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
Expand Down Expand Up @@ -116,7 +116,6 @@ System.Diagnostics.DiagnosticSource</PackageDescription>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Compile Include="System\Diagnostics\HttpHandlerDiagnosticListener.cs" />
noahfalk marked this conversation as resolved.
Show resolved Hide resolved
<Compile Include="AssemblyInfo.netfx.cs" />
<Compile Include="System\Diagnostics\Activity.DateTime.netfx.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace System.Diagnostics
/// <summary>
/// Carries the <see cref="Activity.Current"/> changed event data.
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public readonly struct ActivityChangedEventArgs
{
internal ActivityChangedEventArgs(Activity? previous, Activity? current)
Expand Down Expand Up @@ -219,9 +216,6 @@ public string DisplayName
/// </example>
public string? Id
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get
{
// if we represented it as a traceId-spanId, convert it to a string.
Expand Down Expand Up @@ -250,9 +244,6 @@ public string? Id
/// </summary>
public string? ParentId
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get
{
// if we represented it as a traceId-spanId, convert it to a string.
Expand Down Expand Up @@ -791,9 +782,6 @@ public string? TraceStateString
/// </summary>
public ActivitySpanId SpanId
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get
{
if (_spanId is null)
Expand Down Expand Up @@ -863,9 +851,6 @@ public ActivityTraceFlags ActivityTraceFlags
/// </summary>
public ActivitySpanId ParentSpanId
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get
{
if (_parentSpanId is null)
Expand Down Expand Up @@ -971,9 +956,6 @@ private static bool IsW3CId(string id)
(id[0] != 'f' || id[1] != 'f');
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
internal static bool TryConvertIdToContext(string traceParent, string? traceState, bool isRemote, out ActivityContext context)
{
context = default;
Expand Down Expand Up @@ -1279,9 +1261,6 @@ private string AppendSuffix(string parentId, string suffix, char delimiter)
}
#pragma warning restore CA1822

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
private static unsafe long GetRandomNumber()
{
// Use the first 8 bytes of the GUID as a random number.
Expand All @@ -1300,9 +1279,6 @@ private static bool ValidateSetCurrent(Activity? activity)
return canSet;
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
private bool TrySetTraceIdFromParent()
{
Debug.Assert(_traceId is null);
Expand All @@ -1325,9 +1301,6 @@ private bool TrySetTraceIdFromParent()
return _traceId != null;
}

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
private void TrySetTraceFlagsFromParent()
{
Debug.Assert(!W3CIdFlagsSet);
Expand Down Expand Up @@ -1770,9 +1743,6 @@ public enum ActivityIdFormat
/// it has to, and caches the string representation after it was created.
/// It is mostly useful as an exchange type.
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public readonly struct ActivityTraceId : IEquatable<ActivityTraceId>
{
private readonly string? _hexString;
Expand Down Expand Up @@ -1954,9 +1924,6 @@ internal static bool IsLowerCaseHexAndNotAllZeros(ReadOnlySpan<char> idData)
/// it has to, and caches the string representation after it was created.
/// It is mostly useful as an exchange type.
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public readonly struct ActivitySpanId : IEquatable<ActivitySpanId>
{
private readonly string? _hexString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ internal ActivityCreationOptions(ActivitySource source, string name, T parent, A

public ActivityTagsCollection SamplingTags
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get
{
if (_samplerTags == null)
Expand All @@ -131,9 +128,6 @@ public ActivityTagsCollection SamplingTags

public ActivityTraceId TraceId
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get
{
if (Parent is ActivityContext && IdFormat == ActivityIdFormat.W3C && _context == default)
Expand All @@ -154,24 +148,14 @@ public ActivityTraceId TraceId
/// </summary>
public string? TraceState
{
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
get => _traceState;

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
init
{
_traceState = value;
}
}

// SetTraceState is to set the _traceState without the need of copying the whole structure.
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
internal void SetTraceState(string? traceState) => Unsafe.AsRef(in _traceState) = traceState;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class Counter<T> : Instrument<T> where T : struct
{
internal Counter(Meter meter, string name, string? unit, string? description) : base(meter, name, unit, description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class Histogram<T> : Instrument<T> where T : struct
{
internal Histogram(Meter meter, string name, string? unit, string? description) : base(meter, name, unit, description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace System.Diagnostics.Metrics
/// <summary>
/// Base class of all Metrics Instrument classes
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public abstract class Instrument
{
internal static KeyValuePair<string, object?>[] EmptyTags => Array.Empty<KeyValuePair<string, object?>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public abstract partial class Instrument<T> : Instrument where T : struct
{
[ThreadStatic]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ namespace System.Diagnostics.Metrics
/// Measurement stores one observed metrics value and its associated tags. This type is used by Observable instruments' Observe() method when reporting current measurements.
/// with the associated tags.
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public readonly struct Measurement<T> where T : struct
{
private readonly KeyValuePair<string, object?>[] _tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace System.Diagnostics.Metrics
/// <summary>
/// Meter is the class responsible for creating and tracking the Instruments.
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public class Meter : IDisposable
{
private static readonly List<Meter> s_allMeters = new List<Meter>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace System.Diagnostics.Metrics
/// <summary>
/// MeterListener is class used to listen to the metrics instrument measurements recording.
/// </summary>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class MeterListener : IDisposable
{
// We use LikedList here so we don't have to take any lock while iterating over the list as we always hold on a node which be either valid or null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class ObservableCounter<T> : ObservableInstrument<T> where T : struct
{
private object _callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class ObservableGauge<T> : ObservableInstrument<T> where T : struct
{
private object _callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public abstract class ObservableInstrument<T> : Instrument where T : struct
{
/// <summary>
Expand All @@ -41,9 +38,6 @@ protected ObservableInstrument(Meter meter, string name, string? unit, string? d
public override bool IsObservable => true;

// Will be called from MeterListener.RecordObservableInstruments for each observable instrument.
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
internal override void Observe(MeterListener listener)
{
object? state = GetSubscriptionState(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class ObservableUpDownCounter<T> : ObservableInstrument<T> where T : struct
{
private object _callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ namespace System.Diagnostics
/// Using more than eight tags will cause allocating memory to store the tags.
/// Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
[StructLayout(LayoutKind.Sequential)]
public struct TagList : IList<KeyValuePair<string, object?>>, IReadOnlyList<KeyValuePair<string, object?>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace System.Diagnostics.Metrics
/// <remarks>
/// This class supports only the following generic parameter types: <see cref="byte" />, <see cref="short" />, <see cref="int" />, <see cref="long" />, <see cref="float" />, <see cref="double" />, and <see cref="decimal" />
/// </remarks>
#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public sealed class UpDownCounter<T> : Instrument<T> where T : struct
{
internal UpDownCounter(Meter meter, string name, string? unit, string? description) : base(meter, name, unit, description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ internal sealed class RandomNumberGenerator

public static RandomNumberGenerator Current => t_random ??= new RandomNumberGenerator();

#if ALLOW_PARTIALLY_TRUSTED_CALLERS
[System.Security.SecuritySafeCriticalAttribute]
#endif
public unsafe RandomNumberGenerator()
{
do
Expand Down