aboutsummaryrefslogtreecommitdiff
path: root/lib/Plugins.Essentials
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-10-22 14:37:11 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-10-22 14:37:11 -0400
commitaef1b25aae6fc27c4557dc7e4c9d75cbe22a1f8f (patch)
tree4c7661218668933f0a27bfca04f79c89b3e81d21 /lib/Plugins.Essentials
parentd997950a29ec3ce29cd652298e678d708218fdad (diff)
partial mimalloc support, native source code packages, and default tasks
Diffstat (limited to 'lib/Plugins.Essentials')
-rw-r--r--lib/Plugins.Essentials/src/Extensions/ConnectionInfoExtensions.cs19
-rw-r--r--lib/Plugins.Essentials/src/HttpEntity.cs11
-rw-r--r--lib/Plugins.Essentials/src/Sessions/ISessionExtensions.cs5
-rw-r--r--lib/Plugins.Essentials/src/Sessions/SessionInfo.cs7
4 files changed, 36 insertions, 6 deletions
diff --git a/lib/Plugins.Essentials/src/Extensions/ConnectionInfoExtensions.cs b/lib/Plugins.Essentials/src/Extensions/ConnectionInfoExtensions.cs
index 0039efa..5e0b04d 100644
--- a/lib/Plugins.Essentials/src/Extensions/ConnectionInfoExtensions.cs
+++ b/lib/Plugins.Essentials/src/Extensions/ConnectionInfoExtensions.cs
@@ -25,6 +25,7 @@
using System;
using System.Net;
using System.Linq;
+using System.Security.Authentication;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
@@ -419,21 +420,35 @@ namespace VNLib.Plugins.Essentials.Extensions
internal static bool IsSecure(this IConnectionInfo server, bool isTrusted)
{
+ bool isSecure = GetSslProtocol(server) != SslProtocols.None;
+
//If the connection is not trusted, then ignore header parsing
if (isTrusted)
{
//Standard https protocol header
string? protocol = server.Headers[X_FORWARDED_PROTO_HEADER];
//If the header is set and equals https then tls is being used
- return string.IsNullOrWhiteSpace(protocol) ? server.IsSecure : "https".Equals(protocol, StringComparison.OrdinalIgnoreCase);
+ return string.IsNullOrWhiteSpace(protocol) ? isSecure : "https".Equals(protocol, StringComparison.OrdinalIgnoreCase);
}
else
{
- return server.IsSecure;
+ return isSecure;
}
}
/// <summary>
+ /// Gets the ssl protocol used for the connection, or <see cref="SslProtocols.None"/>
+ /// if transport security is not being used
+ /// </summary>
+ /// <param name="server"></param>
+ /// <returns>The <see cref="SslProtocols"/> the current connection is using</returns>
+ public static SslProtocols GetSslProtocol(this IConnectionInfo server)
+ {
+ ref readonly TransportSecurityInfo? tsi = ref server.GetTransportSecurityInfo();
+ return tsi.HasValue ? tsi.Value.SslProtocol : SslProtocols.None;
+ }
+
+ /// <summary>
/// Was the connection made on a local network to the server? NOTE: Use with caution
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/lib/Plugins.Essentials/src/HttpEntity.cs b/lib/Plugins.Essentials/src/HttpEntity.cs
index 6487ca3..64f18ec 100644
--- a/lib/Plugins.Essentials/src/HttpEntity.cs
+++ b/lib/Plugins.Essentials/src/HttpEntity.cs
@@ -111,23 +111,28 @@ namespace VNLib.Plugins.Essentials
/// A token that has a scheduled timeout to signal the cancellation of the entity event
/// </summary>
public CancellationToken EventCancellation => EventCts.Token;
+
/// <summary>
/// The session associated with the event
/// </summary>
public ref readonly SessionInfo Session => ref _session;
+
/// <summary>
/// A value that indicates if the connecion came from a trusted downstream server
/// </summary>
public readonly bool IsBehindDownStreamServer;
+
/// <summary>
/// Determines if the connection came from the local network to the current server
/// </summary>
public readonly bool IsLocalConnection;
+
/// <summary>
/// Gets a value that determines if the connection is using tls, locally
/// or behind a trusted downstream server that is using tls.
/// </summary>
public readonly bool IsSecure;
+
/// <summary>
/// Caches a <see cref="DateTimeOffset"/> that was created when the connection was created.
/// The approximate current UTC time
@@ -138,26 +143,32 @@ namespace VNLib.Plugins.Essentials
/// The connection info object assocated with the entity
/// </summary>
public IConnectionInfo Server => Entity.Server;
+
/// <summary>
/// User's ip. If the connection is behind a local proxy, returns the users actual IP. Otherwise returns the connection ip.
/// </summary>
public readonly IPAddress TrustedRemoteIp;
+
/// <summary>
/// The requested web root. Provides additional site information
/// </summary>
public readonly IWebProcessor RequestedRoot;
+
/// <summary>
/// If the request has query arguments they are stored in key value format
/// </summary>
public IReadOnlyDictionary<string, string> QueryArgs => Entity.QueryArgs;
+
/// <summary>
/// If the request body has form data or url encoded arguments they are stored in key value format
/// </summary>
public IReadOnlyDictionary<string, string> RequestArgs => Entity.RequestArgs;
+
/// <summary>
/// Contains all files upladed with current request
/// </summary>
public IReadOnlyList<FileUpload> Files => Entity.Files;
+
///<inheritdoc/>
HttpServer IHttpEvent.OriginServer => Entity.OriginServer;
diff --git a/lib/Plugins.Essentials/src/Sessions/ISessionExtensions.cs b/lib/Plugins.Essentials/src/Sessions/ISessionExtensions.cs
index 018c9a2..d3fc475 100644
--- a/lib/Plugins.Essentials/src/Sessions/ISessionExtensions.cs
+++ b/lib/Plugins.Essentials/src/Sessions/ISessionExtensions.cs
@@ -29,8 +29,7 @@ using System.Runtime.CompilerServices;
using VNLib.Net.Http;
using VNLib.Utils;
using VNLib.Utils.Extensions;
-
-#nullable disable
+using VNLib.Plugins.Essentials.Extensions;
namespace VNLib.Plugins.Essentials.Sessions
{
@@ -81,7 +80,7 @@ namespace VNLib.Plugins.Essentials.Sessions
session.IsCrossOrigin(ci.CrossOrigin);
session.SetOrigin(ci.Origin?.ToString());
session.SetRefer(ci.Referer?.ToString());
- session.SetSecurityProtocol(ci.SecurityProtocol);
+ session.SetSecurityProtocol(ci.GetSslProtocol());
session.SetUserAgent(ci.UserAgent);
}
diff --git a/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs b/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs
index 527792f..7cb2783 100644
--- a/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs
+++ b/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs
@@ -30,6 +30,7 @@ using System.Runtime.CompilerServices;
using VNLib.Utils;
using VNLib.Net.Http;
+using VNLib.Plugins.Essentials.Extensions;
using static VNLib.Plugins.Essentials.Statics;
@@ -264,7 +265,7 @@ namespace VNLib.Plugins.Essentials.Sessions
//Since all values will be the same as the connection, cache the connection values
UserAgent = ci.UserAgent;
SpecifiedOrigin = ci.Origin;
- SecurityProcol = ci.SecurityProtocol;
+ SecurityProcol = ci.GetSslProtocol();
flags |= ci.CrossOrigin ? SessionFlags.IsCrossOrigin : SessionFlags.None;
}
@@ -287,12 +288,16 @@ namespace VNLib.Plugins.Essentials.Sessions
///<inheritdoc/>
public bool Equals(SessionInfo other) => SessionID.Equals(other.SessionID, StringComparison.Ordinal);
+
///<inheritdoc/>
public override bool Equals(object? obj) => obj is SessionInfo si && Equals(si);
+
///<inheritdoc/>
public override int GetHashCode() => SessionID.GetHashCode(StringComparison.Ordinal);
+
///<inheritdoc/>
public static bool operator ==(SessionInfo left, SessionInfo right) => left.Equals(right);
+
///<inheritdoc/>
public static bool operator !=(SessionInfo left, SessionInfo right) => !(left == right);