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>
96 lines
4.9 KiB
C#
96 lines
4.9 KiB
C#
using System.Globalization;
|
|
using System.Text;
|
|
using System.Text.Json.Nodes;
|
|
|
|
namespace Febe.SitoDiProva;
|
|
|
|
/// <summary>
|
|
/// The modules of the pages (issue #36, S4): a tiny registry of its own (<c>__d</c> to declare a module,
|
|
/// <c>require</c> to read it, an error for an unknown name) with the values a real site's page holds and the copy at
|
|
/// «Ho finito» reads — tokens, account, version fields, the doc_id of each GraphQL query. The names are the test
|
|
/// site's own (the <c>page</c> section of <c>richieste.prova.json</c>), never Instagram's; the values are the
|
|
/// constants the site checks in <c>/api/</c>.
|
|
/// </summary>
|
|
public sealed partial class TestSite
|
|
{
|
|
/// <summary>The suffix of the module that exports the doc_id of a GraphQL query: <c>ProvaProfiloQuery_operazioneProva</c>.</summary>
|
|
public const string DocIdModuleSuffix = "_operazioneProva";
|
|
|
|
/// <summary>
|
|
/// What the pages declare, by module and property, as text (numbers as the page would turn them into text); the
|
|
/// doc_id modules export the value itself (property <c>""</c>).
|
|
/// </summary>
|
|
/// <param name="accountId">The id of the account the pages show as connected (<see cref="World.Viewer"/>).</param>
|
|
public static IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> PageModules(string accountId)
|
|
{
|
|
var modules = new Dictionary<string, IReadOnlyDictionary<string, string>>(StringComparer.Ordinal);
|
|
foreach (var (name, module) in Modules(accountId))
|
|
{
|
|
modules[name] = module is JsonObject properties
|
|
? properties.ToDictionary(p => p.Key, p => Text(p.Value), StringComparer.Ordinal)
|
|
: new Dictionary<string, string>(StringComparer.Ordinal) { [string.Empty] = Text(module) };
|
|
}
|
|
|
|
return modules;
|
|
}
|
|
|
|
/// <summary>The inline script of the registry, for the head of every page but the verification and session-ended ones.</summary>
|
|
internal static string ModuleRegistryScript(string accountId)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.Append("<script>(function () {\n");
|
|
text.Append(" var declared = {}, made = {};\n");
|
|
text.Append(" var own = function (o, k) { return Object.prototype.hasOwnProperty.call(o, k); };\n");
|
|
text.Append(" window.__d = function (name, deps, factory) { declared[name] = factory; };\n");
|
|
text.Append(" window.require = function (name) {\n");
|
|
text.Append(" if (own(made, name)) { return made[name].exports; }\n");
|
|
text.Append(" if (!own(declared, name)) { throw new Error('Modulo sconosciuto: ' + name); }\n");
|
|
text.Append(" var module = { exports: {} };\n");
|
|
text.Append(" made[name] = module;\n");
|
|
text.Append(" declared[name](module);\n");
|
|
text.Append(" return module.exports;\n");
|
|
text.Append(" };\n");
|
|
foreach (var (name, module) in Modules(accountId))
|
|
{
|
|
// JSON text in a script: the serializer escapes «<», so no value can close the element.
|
|
text.Append(CultureInfo.InvariantCulture, $" __d({JsonValue.Create(name).ToJsonString()}, [], function (module) {{ module.exports = {module!.ToJsonString()}; }});\n");
|
|
}
|
|
|
|
text.Append("})();</script>");
|
|
return text.ToString();
|
|
}
|
|
|
|
/// <summary>Puts <paramref name="script"/> first in the head of <paramref name="html"/>.</summary>
|
|
internal static string InsertAfterHead(string html, string script)
|
|
{
|
|
var at = html.IndexOf("<head>", StringComparison.Ordinal);
|
|
return at < 0 ? html : html.Insert(at + "<head>".Length, script);
|
|
}
|
|
|
|
private static IEnumerable<(string Name, JsonNode Module)> Modules(string accountId)
|
|
{
|
|
yield return ("GettoniProva", new JsonObject { ["lsd"] = Lsd, ["dtsg"] = Dtsg });
|
|
yield return ("UtenteProva", new JsonObject { ["id"] = accountId, ["applicazione"] = AppId });
|
|
yield return ("VersioneProva", new JsonObject
|
|
{
|
|
["revisione"] = Revision,
|
|
["hs"] = HasteSession,
|
|
["hsi"] = HasteSessionId,
|
|
|
|
// Numbers in the page, as a real page keeps them: the copy turns them into text.
|
|
["dpr"] = int.Parse(Dpr, CultureInfo.InvariantCulture),
|
|
["comet"] = int.Parse(CometReq, CultureInfo.InvariantCulture),
|
|
});
|
|
yield return ("ConnessioneProva", new JsonObject { ["classe"] = ConnectionClass });
|
|
yield return ("AvvioProva", new JsonObject { ["nonce"] = EntryNonce });
|
|
foreach (var (operation, docId) in DocIds.OrderBy(d => d.Key, StringComparer.Ordinal))
|
|
{
|
|
yield return (operation + DocIdModuleSuffix, JsonValue.Create(docId));
|
|
}
|
|
}
|
|
|
|
private static string Text(JsonNode? node) => node is JsonValue value && value.TryGetValue<int>(out var number)
|
|
? number.ToString(CultureInfo.InvariantCulture)
|
|
: node?.GetValue<string>() ?? string.Empty;
|
|
}
|