Sessione salvata cifrata, copiata a «Ho finito» (#36, S4)
Il client del sito ha bisogno della sessione del browser di Febe: ora la copia c'è, cifrata e dietro un interruttore, senza cambiare nulla di predefinito. - Opzione «raccolta» (pagine predefinita, richieste): solo con «richieste» e almeno un'operazione configurata si costruiscono sessione salvata, client del sito e copia. Con Instagram nulla cambia: le dieci operazioni restano non configurate (mancano __spin_*, __req, __s, __dyn, __csr e altri). - Cookie con dominio, percorso, solo-host, Secure, HttpOnly e scadenza, mandati solo dove il browser li manderebbe (RFC 6265). - Sezione «page» del catalogo: dove la pagina tiene ogni valore; nuovi campi rev, hs, hsi, dpr, ccg, comet_req, entry_nonce. Il caricatore rifiuta un'operazione configurata con un valore di sessione senza fonte nella pagina. - Dati/sessione/sessione.json: DPAPI su Windows, AES-256-GCM in Docker (chiave da FEBE_CHIAVE_SESSIONE o chiave.bin), scrittura atomica, file illeggibile = nessuna sessione. «Scollega» la cancella; chiave.bin resta. - Copia a «Ho finito» con Network.getCookies e una sola Runtime.evaluate in sola lettura, solo da una pagina del sito e finché dura il permesso di guida. - FEBE_PASSWORD e FEBE_CHIAVE_SESSIONE non passano a Chromium, Xvfb, ffmpeg. - Sito di prova: csrftoken, cookie limitato a /api/, registro di moduli suo. - Revisione su tre lenti: 11 punti confermati, tutti corretti. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3046b2da47
commit
c87768766c
69 files changed
+5936
-415
No files matched your search
@@ -1,10 +1,12 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Febe.App;
|
||||
using Febe.Browser.Cdp;
|
||||
using Febe.Browser.Hosting;
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Security;
|
||||
using Febe.Desktop.Core;
|
||||
using Febe.Web.Native;
|
||||
|
||||
@@ -31,6 +33,11 @@ internal sealed class FakeDesktopShell : IDesktopShell
|
||||
/// <summary>Called with each browser as it is created, before Febe uses it (to set up the fake page).</summary>
|
||||
public Action<FakeBrowser>? OnCreated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DPAPI exists only on Windows: here AES-256-GCM, with a key made at run time (never a literal key in the tests).
|
||||
/// </summary>
|
||||
public ISessionProtector SessionProtector { get; } = new AesGcmSessionProtector(RandomNumberGenerator.GetBytes(SessionKey.Length));
|
||||
|
||||
public string? WebView2Version() => RuntimeVersion;
|
||||
|
||||
public IFebeBrowser CreateWebView2Browser(WebView2BrowserSettings settings, FebePlatformContext context)
|
||||
@@ -226,9 +233,44 @@ internal sealed class FakeCdp : ICdpSession
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly Dictionary<string, List<Action<JsonElement>>> _handlers = new(StringComparer.Ordinal);
|
||||
private int _captureReads;
|
||||
private int _cookieReads;
|
||||
|
||||
public bool LoggedIn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// What the copy of the session (issue #36, S4) reads from this page with its one evaluation (the user agent, the
|
||||
/// values and doc_id of the modules); null: the page answers nothing to it. Low-entropy test values only.
|
||||
/// </summary>
|
||||
public JsonObject? PageCapture { get; set; } = DefaultPageCapture();
|
||||
|
||||
/// <summary>How many times the copy's evaluation (the one that reads <c>navigator.userAgent</c>) was asked.</summary>
|
||||
public int CaptureReads => Volatile.Read(ref _captureReads);
|
||||
|
||||
/// <summary>How many times <c>Network.getCookies</c> was asked.</summary>
|
||||
public int CookieReads => Volatile.Read(ref _cookieReads);
|
||||
|
||||
/// <summary>The values of the test site's page, as the copy would find them.</summary>
|
||||
public static JsonObject DefaultPageCapture() => new()
|
||||
{
|
||||
["ua"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Finestra di prova",
|
||||
["values"] = new JsonObject
|
||||
{
|
||||
["lsd"] = Febe.SitoDiProva.TestSite.Lsd,
|
||||
["fb_dtsg"] = Febe.SitoDiProva.TestSite.Dtsg,
|
||||
["app_id"] = Febe.SitoDiProva.TestSite.AppId,
|
||||
["account_id"] = "1234",
|
||||
["rev"] = Febe.SitoDiProva.TestSite.Revision,
|
||||
["hs"] = Febe.SitoDiProva.TestSite.HasteSession,
|
||||
["hsi"] = Febe.SitoDiProva.TestSite.HasteSessionId,
|
||||
["dpr"] = Febe.SitoDiProva.TestSite.Dpr,
|
||||
["comet_req"] = Febe.SitoDiProva.TestSite.CometReq,
|
||||
["ccg"] = Febe.SitoDiProva.TestSite.ConnectionClass,
|
||||
["entry_nonce"] = Febe.SitoDiProva.TestSite.EntryNonce,
|
||||
},
|
||||
["docIds"] = new JsonObject { [Febe.SitoDiProva.TestSite.ProfileQuery] = Febe.SitoDiProva.TestSite.DocIds[Febe.SitoDiProva.TestSite.ProfileQuery] },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Like the test site, which sets its session cookie on any visit: a navigation to an address starting with this
|
||||
/// logs in, and the page reports itself loaded. Null: only the test logs in.
|
||||
@@ -257,8 +299,9 @@ internal sealed class FakeCdp : ICdpSession
|
||||
{
|
||||
"Page.getFrameTree" => new JsonObject { ["frameTree"] = new JsonObject { ["frame"] = new JsonObject { ["id"] = "F1", ["url"] = Url } } },
|
||||
"Page.navigate" => Navigate(parameters),
|
||||
// The session cookie of Instagram, and the test site's one.
|
||||
"Network.getCookies" => new JsonObject { ["cookies"] = LoggedIn ? new JsonArray(new JsonObject { ["name"] = "sessionid" }, new JsonObject { ["name"] = "sessione_prova" }) : new JsonArray() },
|
||||
// The session cookie of Instagram, and the test site's ones (with the values and places the copy keeps).
|
||||
"Network.getCookies" => Cookies(),
|
||||
"Runtime.evaluate" when IsCapture(parameters) => Capture(),
|
||||
"Runtime.evaluate" when LogsInOnVisit is not null => new JsonObject { ["result"] = new JsonObject { ["type"] = "string", ["value"] = "complete" } },
|
||||
_ => new JsonObject(),
|
||||
};
|
||||
@@ -286,6 +329,48 @@ internal sealed class FakeCdp : ICdpSession
|
||||
});
|
||||
}
|
||||
|
||||
private static bool IsCapture(object? parameters) =>
|
||||
(parameters as JsonObject)?["expression"]?.GetValue<string>() is { } expression
|
||||
&& expression.Contains("navigator.userAgent", StringComparison.Ordinal);
|
||||
|
||||
private JsonObject Cookies()
|
||||
{
|
||||
Interlocked.Increment(ref _cookieReads);
|
||||
if (!LoggedIn)
|
||||
{
|
||||
return new JsonObject { ["cookies"] = new JsonArray() };
|
||||
}
|
||||
|
||||
static JsonObject Cookie(string name, string value, string domain, string path = "/") => new()
|
||||
{
|
||||
["name"] = name,
|
||||
["value"] = value,
|
||||
["domain"] = domain,
|
||||
["path"] = path,
|
||||
["expires"] = -1,
|
||||
["session"] = true,
|
||||
["secure"] = false,
|
||||
["httpOnly"] = true,
|
||||
};
|
||||
|
||||
return new JsonObject
|
||||
{
|
||||
["cookies"] = new JsonArray(
|
||||
Cookie("sessionid", "sessione-di-prova", ".instagram.com"),
|
||||
Cookie("sessione_prova", "sessione-di-prova", "127.0.0.1"),
|
||||
Cookie("csrftoken", "csrf-di-prova", "127.0.0.1"),
|
||||
Cookie("percorso_api", "solo-sotto-api", "127.0.0.1", "/api/")),
|
||||
};
|
||||
}
|
||||
|
||||
private JsonObject Capture()
|
||||
{
|
||||
Interlocked.Increment(ref _captureReads);
|
||||
return PageCapture is { } page
|
||||
? new JsonObject { ["result"] = new JsonObject { ["type"] = "object", ["value"] = JsonNode.Parse(page.ToJsonString()) } }
|
||||
: new JsonObject();
|
||||
}
|
||||
|
||||
private JsonObject Navigate(object? parameters)
|
||||
{
|
||||
var url = (parameters as JsonObject)?["url"]?.GetValue<string>();
|
||||
|
||||
Reference in new issue
Block a user