Skip to content

Commit

Permalink
Promote traffic_annotation value
Browse files Browse the repository at this point in the history
Improves #3
  • Loading branch information
Eric Lawrence committed Apr 10, 2020
1 parent 59e2880 commit 96f30cd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
8 changes: 4 additions & 4 deletions FiddlerImportNetlog/FiddlerInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace FiddlerImportNetlog
{
[ProfferFormat("NetLog JSON", "Chromium's JSON-based event log format (v1.2.1). See https://dev.chromium.org/for-testers/providing-network-details for more details.")]
[ProfferFormat("NetLog JSON", "Chromium's JSON-based event log format (v1.2.3). See https://dev.chromium.org/for-testers/providing-network-details for more details.")]
public class HTTPArchiveFormatImport : ISessionImporter
{
public Session[] ImportSessions(string sFormat, Dictionary<string, object> dictOptions, EventHandler<Fiddler.ProgressCallbackEventArgs> evtProgressNotifications)
Expand Down Expand Up @@ -46,7 +46,7 @@ public Session[] ImportSessions(string sFormat, Dictionary<string, object> dictO
oSR = new StreamReader(strmContent);
}
else
{
{
Stream oFS = File.OpenRead(sFilename);

// Check to see if this file data was GZIP'd or PKZIP'd.
Expand Down Expand Up @@ -108,7 +108,7 @@ private MemoryStream GetUnzippedBytes(Stream oFS)
long fileLength = oFS.Length;
if (fileLength > Int32.MaxValue)
throw new IOException("file over 2gb");

int index = 0;
int count = (int)fileLength;
byte[] bytes = new byte[count];
Expand All @@ -125,4 +125,4 @@ private MemoryStream GetUnzippedBytes(Stream oFS)

public void Dispose() { }
}
}
}
37 changes: 26 additions & 11 deletions FiddlerImportNetlog/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Magics
public int SOCKET;

// Events
public int REQUEST_ALIVE;
public int URL_REQUEST_START_JOB;
public int SEND_HEADERS;
public int SEND_QUIC_HEADERS;
Expand Down Expand Up @@ -72,7 +73,7 @@ private static ArrayList FilterExtensions(ArrayList al)
}
return alOut;
}

private static DateTime GetTimeStamp(object o, long baseTime)
{
long t = baseTime;
Expand Down Expand Up @@ -115,7 +116,7 @@ internal NetlogImporter(StreamReader oSR, List<Session> listSessions, EventHandl
FiddlerApplication.DoNotifyUser("This JSON file does not seem to contain NetLog data.", "Unexpected Data");
Session sessFile = Session.BuildFromData(false,
new HTTPRequestHeaders(
String.Format("/file.json"),
String.Format("/file.json"),
new[] { "Host: IMPORTED", "Date: " + DateTime.UtcNow.ToString() }),
Utilities.emptyByteArray,
new HTTPResponseHeaders(200, "File Data", new[] { "Content-Type: application/json; charset=utf-8" }),
Expand Down Expand Up @@ -156,6 +157,7 @@ public bool ExtractSessionsFromJSON(Hashtable htFile)

#region GetEventTypes
// HTTP-level Events
NetLogMagics.REQUEST_ALIVE = getIntValue(htEventTypes["REQUEST_ALIVE"], -987);
NetLogMagics.URL_REQUEST_START_JOB = getIntValue(htEventTypes["URL_REQUEST_START_JOB"], -997);
NetLogMagics.SEND_HEADERS = getIntValue(htEventTypes["HTTP_TRANSACTION_SEND_REQUEST_HEADERS"], -996);
NetLogMagics.SEND_QUIC_HEADERS = getIntValue(htEventTypes["HTTP_TRANSACTION_QUIC_SEND_REQUEST_HEADERS"], -995);
Expand Down Expand Up @@ -231,7 +233,7 @@ public bool ExtractSessionsFromJSON(Hashtable htFile)

_listSessions.Add(Session.BuildFromData(false,
new HTTPRequestHeaders(
String.Format("/Enabled_Extensions"), // TODO: Add Machine name?
String.Format("/ENABLED_EXTENSIONS"), // TODO: Add Machine name?
new[] { "Host: NETLOG" }),
Utilities.emptyByteArray,
new HTTPResponseHeaders(200, "Analyzed Data", new[] { "Content-Type: application/json; charset=utf-8" }),
Expand Down Expand Up @@ -610,7 +612,7 @@ private int GenerateSessionsFromURLRequests(Dictionary<int, List<Hashtable>> dic
int iRequest = 0;
iLastPct = 75;

// Iterate over each URLRequest's events bucket and parse one or more Sessions out of it.
// Iterate over each URLRequest's events bucket and parse one or more Sessions out of it.
foreach (KeyValuePair<int, List<Hashtable>> kvpUR in dictURLRequests)
{
++iRequest;
Expand Down Expand Up @@ -640,6 +642,7 @@ private void ParseSessionsFromBucket(KeyValuePair<int, List<Hashtable>> kvpUR)

string sURL = String.Empty;
string sMethod = "GET";
string sTrafficAnnotation = String.Empty;
SessionTimers oTimers = new SessionTimers();

int cbDroppedResponseBody = 0;
Expand All @@ -657,6 +660,11 @@ private void ParseSessionsFromBucket(KeyValuePair<int, List<Hashtable>> kvpUR)

#region ParseImportantEvents
// C# cannot |switch()| on non-constant case values. Hrmph.
if (iType == NetLogMagics.REQUEST_ALIVE)
{
sTrafficAnnotation = getIntValue(htParams["traffic_annotation"], 0).ToString();
continue;
}
if (iType == NetLogMagics.URL_REQUEST_START_JOB)
{
if (bHasStartJob)
Expand All @@ -679,6 +687,7 @@ private void ParseSessionsFromBucket(KeyValuePair<int, List<Hashtable>> kvpUR)
sMethod = (string)htParams["method"];
dictSessionFlags["X-Netlog-URLRequest-ID"] = kvpUR.Key.ToString();
dictSessionFlags["X-ProcessInfo"] = String.Format("{0}:0", sClient);
dictSessionFlags["X-Netlog-Traffic_Annotation"] = sTrafficAnnotation;

// In case we don't get these later.
oTimers.ClientBeginRequest = oTimers.FiddlerGotRequestHeaders = oTimers.FiddlerBeginRequest = GetTimeStamp(htEvent["time"], baseTime);
Expand Down Expand Up @@ -726,13 +735,19 @@ private void ParseSessionsFromBucket(KeyValuePair<int, List<Hashtable>> kvpUR)

if (iType == NetLogMagics.COOKIE_INCLUSION_STATUS)
{
string sCookieName = (htParams["name"] as string) ?? "(name-unavailable)";
string sOperation = (htParams["operation"] as string) ?? String.Empty;
string sExclusionReasons = (htParams["exclusion_reason"] as string) ?? String.Empty;
// {"params":
// { "exclusion_reason":"EXCLUDE_SAMESITE_LAX, DO_NOT_WARN", "name"="foo", "operation"="store"},
// "source":{"id":3431,"type":1}
// "COOKIE_INCLUSION_STATUS":411
string sCookieName = (htParams["name"] as string) ?? "(name-unavailable)";
// TODO: As of Chrome 81, CookieInclusionStatusNetLogParams also adds |domain| and |path| attributes available if "sensitive" data is included.

// In Chrome 81.3993, the |exclusion_reason| field was renamed to |status| because the |cookie_inclusion_status| entries are
// now also emitted for included cookies.
string sExclusionReasons = (htParams["exclusion_reason"] as string);
if (String.IsNullOrEmpty(sExclusionReasons)) sExclusionReasons = (htParams["status"] as string) ?? String.Empty;

// If the log indicates that the cookie was included, just skip it for now.
// TODO: Offer a richer cookie-debugging story that exposes the domain/path/and inclusion status.
// https://source.chromium.org/chromium/chromium/src/+/master:net/cookies/canonical_cookie.cc;l=899?q=GetDebugString%20cookie&ss=chromium&originalUrl=https:%2F%2Fcs.chromium.org%2F
if (sExclusionReasons.OICContains("include")) continue;

// See |ExclusionReason| list in https://cs.chromium.org/chromium/src/net/cookies/canonical_cookie.h?type=cs&q=EXCLUDE_SAMESITE_LAX&sq=package:chromium&g=0&l=304
// EXCLUDE_HTTP_ONLY, EXCLUDE_SECURE_ONLY,EXCLUDE_DOMAIN_MISMATCH,EXCLUDE_NOT_ON_PATH,EXCLUDE_INVALID_PREFIX
Expand Down Expand Up @@ -831,7 +846,7 @@ private static void AnnotateHeadersWithUnstoredCookies(HTTPResponseHeaders oRPH,
listExclusions.Clear();
}

private void BuildAndAddSession(ref SessionFlags oSF, ref HTTPRequestHeaders oRQH, HTTPResponseHeaders oRPH, MemoryStream msResponseBody,
private void BuildAndAddSession(ref SessionFlags oSF, ref HTTPRequestHeaders oRQH, HTTPResponseHeaders oRPH, MemoryStream msResponseBody,
Dictionary<string, string> dictSessionFlags, string sURL, string sMethod, SessionTimers oTimers, int cbDroppedResponseBody)
{
// TODO: Sanity-check missing headers.
Expand Down
8 changes: 7 additions & 1 deletion FiddlerImportNetlog/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
[assembly: AssemblyCopyright("Copyright ©2019 Eric Lawrence")]
[assembly: System.Resources.NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.2.1.0")] // ALWAYS UPDATE THE VERSION in the [ProfferFormat] attribute to match!
[assembly: AssemblyVersion("1.2.3.0")] // ALWAYS UPDATE THE VERSION in the [ProfferFormat] attribute to match!
[assembly: Fiddler.RequiredVersion("4.6.0.0")]

// v1.2.3
// Add |traffic_annotation| to session properties

// v1.2.2
// Update Cookie Inclusion reasons to match latest CL 81.0.3993 https://chromium-review.googlesource.com/c/chromium/src/+/1960865

// v1.2.1
// Add Cookie Exclusion warnings

Expand Down

0 comments on commit 96f30cd

Please sign in to comment.