Skip to content

Commit

Permalink
Better sessionID generation
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Apr 3, 2024
1 parent 44dec3a commit 423cd15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Security.Cryptography;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -57,6 +57,7 @@ public sealed class ArchiWebHandler : IDisposable {
private const string EconService = "IEconService";
private const string LoyaltyRewardsService = "ILoyaltyRewardsService";
private const byte MinimumSessionValidityInSeconds = 10;
private const byte SessionIDLength = 24; // For maximum compatibility, should be divisible by 2 and match the length of "sessionid" property that Steam uses across their websites
private const string SteamAppsService = "ISteamApps";

[PublicAPI]
Expand Down Expand Up @@ -2048,7 +2049,9 @@ internal async Task<bool> Init(ulong steamID, EUniverse universe, string accessT

Initialized = false;

string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString(CultureInfo.InvariantCulture)));
#pragma warning disable CA1308 // False positive, we're intentionally converting this part to lowercase and it's not used for any security decisions based on the result of the normalization
string sessionID = Convert.ToHexString(RandomNumberGenerator.GetBytes(SessionIDLength / 2)).ToLowerInvariant();
#pragma warning restore CA1308 // False positive, we're intentionally converting this part to lowercase and it's not used for any security decisions based on the result of the normalization

WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", $".{SteamCheckoutURL.Host}"));
WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", $".{SteamCommunityURL.Host}"));
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>6.0.1.25</Version>
<Version>6.0.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 423cd15

Please sign in to comment.