Dopo una prova dal vivo andata male, Alberto deve poter mandare un solo file che spieghi perché, senza che nessuno veda dati di altre persone. Attività ha ora il pulsante «Diagnostica», che scarica il rapporto delle sessioni degli ultimi 14 giorni: pagine aperte e forma degli indirizzi, risposte per tipo, stato e dimensione con ciò che i lettori ne hanno fatto, struttura stretta delle forme sconosciute, ricette, segnali, permessi negati, file in coda e scaricati, e il motivo di ogni arresto. Nel rapporto entrano solo valori da elenchi chiusi, numeri, orari e forme: mai nomi, indirizzi completi, codici, cursori, cookie o pezzi di risposte. Le forme degli indirizzi e la regola delle chiavi-dato passano dalla sonda a Core, e la sonda le richiama. Il registratore non lancia mai eccezioni verso la raccolta e tiene i file in Dati/diagnostica per 14 giorni. Prova che il rapporto non contiene valori, con controlli di mutazione; tre giri di revisione avversaria (25 difetti confermati, tutti corretti). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
5.0 KiB
C#
120 lines
5.0 KiB
C#
namespace Febe.Core.Collection.Privacy;
|
|
|
|
/// <summary>
|
|
/// Turns an address path into a pattern that names nobody (issue #34, issue #39): every segment that is not a known word
|
|
/// of the site's addresses becomes <c>{numero}</c> or <c>{testo}</c>. Used by the request shapes of the probe and by the
|
|
/// diagnostic report. A missing word only costs detail, never privacy.
|
|
/// </summary>
|
|
public static class PathPatterns
|
|
{
|
|
/// <summary>Written in place of a segment made only of digits.</summary>
|
|
public const string Number = "{numero}";
|
|
|
|
/// <summary>Written in place of any other segment that is not a known word.</summary>
|
|
public const string Text = "{testo}";
|
|
|
|
/// <summary>
|
|
/// Path segments kept as they are: words of the site's addresses, the same for everyone. Anything else (user names,
|
|
/// identifiers, codes) becomes <see cref="Number"/> or <see cref="Text"/>.
|
|
/// </summary>
|
|
private static readonly HashSet<string> Known = new(StringComparer.Ordinal)
|
|
{
|
|
"api", "v1", "graphql", "graphql_www", "query", "ajax", "bulk-route-definitions", "navigation", "web", "users",
|
|
"user", "web_profile_info", "usernameinfo", "info", "feed", "timeline", "reels_media", "reels_tray", "highlights",
|
|
"highlights_tray", "friendships", "following", "followers", "show", "show_many", "search", "topsearch", "fbsearch",
|
|
"web_search", "typeahead", "accounts_typeahead", "top_serp", "media", "comments", "usertags", "clips", "stories",
|
|
"story", "tags", "sections", "discover", "explore", "chaining", "profile", "posts", "reels", "tagged", "saved",
|
|
"qp", "batch_fetch_web", "logging_client_events", "direct_v2", "inbox", "has_new", "get_presence", "wwwgraphql",
|
|
"ig", "bz", "web_info", "current_user", "user_info", "locations", "seen", "media_seen", "reel", "p", "accounts",
|
|
"edit", "activity", "news", "inbox_v2", "notifications", "badge", "home", "graphql_query",
|
|
|
|
// Fixed roots of the site's own pages (verification, login, messages...): a stop that lands there must say so,
|
|
// not «/{testo}/», and the site map must not take them for a profile (SiteMap.Classify).
|
|
"challenge", "checkpoint", "direct", "login", "logout", "emails", "password", "reset", "two_factor", "onetap",
|
|
"suspended", "consent", "settings", "help", "legal", "privacy", "terms", "about",
|
|
};
|
|
|
|
/// <summary>
|
|
/// File extensions a CDN or other address may show in a report: a closed list, so that the last part of a name
|
|
/// with a dot («nome.cognome») never passes as an extension.
|
|
/// </summary>
|
|
private static readonly HashSet<string> Extensions = new(StringComparer.Ordinal)
|
|
{
|
|
"jpg", "jpeg", "png", "webp", "heic", "gif", "avif", "mp4", "m4a", "m4v", "webm", "mov", "js", "css", "json",
|
|
"woff", "woff2", "ttf", "ico", "svg", "html", "txt",
|
|
};
|
|
|
|
/// <summary>The known words, the same for everyone.</summary>
|
|
public static IReadOnlySet<string> KnownSegments => Known;
|
|
|
|
/// <summary>The extensions <see cref="ExtensionOf"/> may answer.</summary>
|
|
public static IReadOnlySet<string> KnownExtensions => Extensions;
|
|
|
|
/// <summary>The path with each segment that is not a known word replaced by <c>{numero}</c> or <c>{testo}</c>.</summary>
|
|
/// <remarks>Anything after «?» or «#» is dropped first: only a path is a path.</remarks>
|
|
public static string Of(string path)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(path);
|
|
var cut = path.IndexOfAny(['?', '#']);
|
|
if (cut >= 0)
|
|
{
|
|
path = path[..cut];
|
|
}
|
|
|
|
var segments = path.Split('/');
|
|
for (var i = 0; i < segments.Length; i++)
|
|
{
|
|
var segment = segments[i];
|
|
if (segment.Length == 0 || Known.Contains(segment))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
segments[i] = IsDigits(segment) ? Number : Text;
|
|
}
|
|
|
|
return string.Join('/', segments);
|
|
}
|
|
|
|
/// <summary>True for a word of the site kept by <see cref="Of"/>.</summary>
|
|
public static bool IsKnownSegment(string segment) => Known.Contains(segment);
|
|
|
|
/// <summary>The extension of the last segment of <paramref name="path"/> (lower case, no dot) when it is on the closed list; otherwise null.</summary>
|
|
public static string? ExtensionOf(string? path)
|
|
{
|
|
if (string.IsNullOrEmpty(path))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var cut = path.IndexOfAny(['?', '#']);
|
|
if (cut >= 0)
|
|
{
|
|
path = path[..cut];
|
|
}
|
|
|
|
var last = path[(path.LastIndexOf('/') + 1)..];
|
|
var dot = last.LastIndexOf('.');
|
|
if (dot < 0 || dot == last.Length - 1)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var extension = last[(dot + 1)..].ToLowerInvariant();
|
|
return Extensions.Contains(extension) ? extension : null;
|
|
}
|
|
|
|
private static bool IsDigits(string segment)
|
|
{
|
|
foreach (var c in segment)
|
|
{
|
|
if (!char.IsAsciiDigit(c))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return segment.Length > 0;
|
|
}
|
|
}
|