Skip to content

Export is null on certain conditions #69

Closed

Description

@bzbzh

For certain SAML traces it occured to me than the export return an empty file (in fact a file with "null" inside).

An error raises here:

const createFromJSON = function(obj) {
      let stringified = JSON.stringify(obj);
      return JSON.parse(stringified);
    };

    const enrichWithResponse = (req, res) => {
      let responseCopy = createFromJSON(res);
      req.responseStatus = responseCopy.statusCode;
      req.responseStatusText = responseCopy.statusLine;
      req.responseHeaders = responseCopy.responseHeaders;
    };

    let reqscopy = reqs.map(req => {
      let newRequest = createFromJSON(req);
      enrichWithResponse(newRequest, req.getResponse());

      the_filters.forEach(filter => filter(newRequest));
      return newRequest;
    });

When trying to stringify "req.getResponse()" when it returns null.

I wonder if it would be a good solution to alter this:

  'attachHeadersToRequest' : function(request) { // onBeforeSendHeaders
    let uniqueRequestId = new SAMLTrace.UniqueRequestId(request.requestId, request.method, request.url);
    uniqueRequestId.create(id => {
      let tracer = SAMLTrace.TraceWindow.instance();

      // Maybe revise the HTTP method on redirected requests
      let alterationResult = tracer.reviseRedirectedRequestMethod(request, id);
      id = alterationResult.id;

      let entry = tracer.httpRequests.find(req => req.id === id);
      if (!entry) {
        // Skip further execution if no precedingly issued request can be found. This may occur, if tracing
        // new requests is paused. Requests that were issued before pausing will be found and handled.
        return;
      }

      entry.headers = request.requestHeaders;
      tracer.addRequestItem(entry, () => entry.res);
      tracer.updateStatusBar();
    });
  },

In particular:
tracer.addRequestItem(entry, () => entry.res);
to
tracer.addRequestItem(entry, () => entry.res || {});
or so

So the whole trace can be exported dispite one of them acts oddly.

Activity

  1. thijskh commented on Oct 18, 2021

    @thijskh
    Member

    Any idea what the exact issue is with that request? Is that visible in the tracer view?

  2. bzbzh commented on Oct 18, 2021

    @bzbzh
    Author

    Yes it is.
    No idea at this point.

  3. kellenmurphy commented on Aug 1, 2022

    @kellenmurphy
    Contributor

    @bzbzh were any of the traced events blocked by Firefox due to a security warning, i.e. for a self-signed certificate which hadn't been accepted? Or which had popped the warning and then you accepted to proceed anyway? i.e. see: #66 (comment)

    I'm able to replicate the trace js error that causes a null export under that condition.

  4. bzbzh commented on Aug 1, 2022

    @bzbzh
    Author

    @kellenmurphy I have no "Accept Risk and Continue" message. The certificate is a let's encrypt one. Is there another way/thing to test?

  5. kellenmurphy commented on Aug 1, 2022

    @kellenmurphy
    Contributor

    @bzbzh Okay, no need for more testing... it is telling though that there's something odd about certain traces. I'm going to dig on the thread I have re: self-signed cert warnings to see if I can isolate why that gets the null... and maybe we'll solve your problem as well in the meantime?

  6. khlr commented on Nov 11, 2023

    @khlr
    Contributor

    I'm able to replicate the trace js error that causes a null export under that condition.

    Hm... So @kellenmurphy was able to replicate this... I wasn't. I used the super-handy testing website https://badssl.com.
    Clicking e.g. the expired link leads to SAML-tracer tracing the request without any response (due to the blocking by the browser).

    However, this trace can still be exported without any problems. The response-less request simply does not end up in the output. Ok, that could of course also be considered an error. But that would probably be a separate topic.

    What exactly do you have to do to recreate the null error?

  7. chris18890 commented on Feb 6, 2024

    @chris18890

    I seem to have come across the same issue

    Env/actions:

    I'm able to see the results of the SAML trace onscreen, but when I do an export I get a 4 byte file that just has the word "null" printed in it.

  8. tvdijen commented on Feb 6, 2024

    @tvdijen
    Member

    Unfortunately that's not reproducible for us @chris18890 ...

  9. thijskh commented on Feb 6, 2024

    @thijskh
    Member

    It would be great if someone who encounters this issue and can actually reproduce it, could see if they can debug it/find the cause.

  10. chris18890 commented on Feb 7, 2024

    @chris18890

    Oddly enough though, it worked perfectly on firefox!

    Unfortunately that's not reproducible for us @chris18890 ...

    Is there anything I can help with in terms of reproducing it?

  11. tvdijen commented on Feb 7, 2024

    @tvdijen
    Member

    @chris18890 If you can reproduce it, you could try and opening the 'developer tools' in your add-on window and see if anything is being blocked why you try to export.

  12. BryanSD commented on Apr 26, 2024

    @BryanSD

    I believe I ran into this issue as well, and may have steps to reproduce in Firefox. You can contrive a scenario where this works in the context of a SAML exchange, but it's equally present on a visit to google.com:

    1. Open up the Web Developer Tools in Firefox and enable Request Blocking (icon looks like 🚫).
    2. Add google.com as a resource to block.
    3. Open SAML Tracer
    4. Back in Firefox, navigate to google.com
    5. Notice in the Network tab any requests to google.com show "Blocked by DevTools"
    6. Notice the corresponding requests in SAML Tracer are grayed out.
    7. Attempt to Export from SAML Tracer. Note that 0 requests can be exported. (if any other entries are present and an export can be accomplished, then re-import it and notice the google.com requests are missing)

    This reproduction works because, from my understanding, a bug in Request Blocking in Firefox allows the request to actually be sent but the response is ignored: https://bugzilla.mozilla.org/show_bug.cgi?id=1756770

    The real-life use-case where I saw this occurred when JS in the page was cancelling the request before it could ever complete - the request went out, but it was cancelled before the response was received. However, no record of the request could be found in a SAML Tracer export even though it appeared "live" when viewing the network activity there.

  13. KLuK9 commented on Nov 29, 2024

    @KLuK9

    @chris18890 If you can reproduce it, you could try and opening the 'developer tools' in your add-on window and see if anything is being blocked why you try to export.

    Here is the error in the console log when I click on "export" (the one in the toolbar, not the one in the pop-up):

    Uncaught SyntaxError: "undefined" is not valid JSON
        at JSON.parse (<anonymous>)
        at createFromJSON (SAMLTraceIO.js:180:19)
        at enrichWithResponse (SAMLTraceIO.js:184:26)
        at SAMLTraceIO.js:192:7
        at Array.map (<anonymous>)
        at SAMLTraceIO.ExportFilter.perform (SAMLTraceIO.js:190:25)
        at SAMLTraceIO.exportRequests (SAMLTraceIO.js:26:27)
        at Object.createExportResult (exportDialog.js:66:26)
        at Object.setupContent (exportDialog.js:60:8)
        at HTMLDivElement.<anonymous> (ui.js:95:44)
    

    In the pop-up, if I hover the "export" button, this is the preview URL
    image

    Windows 10 22H2
    Google Chrome Version 131.0.6778.86

  14. tvdijen commented on Nov 29, 2024

    @tvdijen
    Member

    I have the same setup of Windows and Chrome-version, but I cannot reproduce this at all.. I'm suspecting that this issue is related to some other add-on like a script-blocker..

  15. KLuK9 commented on Nov 29, 2024

    @KLuK9

    I just disabled uBlock Origin and everything works fine now! Thank you.
    Since it's a very popular extension, perhaps all the problems come from there, or from other ad blockers.

  16. tvdijen commented on Nov 29, 2024

    @tvdijen
    Member

    It must be some non-default setting @KLuK9, because I installed that add-on and SAML-tracer export keeps working.

  17. sullivan1337 commented on Mar 5, 2025

    @sullivan1337

    I had this exact same problem, and was able to fix it in the export by clearing the Filter resources toggle..
    Seems counterintuitive, but with that enabled the export seems to miss a bunch of data.

  18. tvdijen commented on Mar 5, 2025

    @tvdijen
    Member

    @sullivan1337 Missing a bunch of data is to be expected if you filter resources.. Perfectly normal behaviour. This ticket is about exporting and then end up with empty files.

  19. sullivan1337 commented on Mar 5, 2025

    @sullivan1337

    The behavior I was seeing was if Filtered resources was toggled on, my files were missing all SAML requests or empty all-together.
    As soon as I disabled the Filter, all the expected results and traffic were then included.

    Just trying to help out as I was experiencing almost identical behavior as others in this thread.

  20. tvdijen commented on Mar 5, 2025

    @tvdijen
    Member

    Thanks! That's useful info! Any other add-ons in place?

  21. DavidCSloaneHKS commented on May 20, 2025

    @DavidCSloaneHKS

    Seeing this same behavior in Firefox for Windows 138.04, on Windows 11 23H2 with current patches. SAML Tracer and 1Password are the only enabled extensions. I have UBlock Origin but I've disabled it to try and fix SAML-tracer. I can see dozens of SAML-tagged entries in the SAML-tracer window, but export only produces a file containing "null", whether "Filter resources" is checked or un-checked. Any suggestions would be welcome.

  22. gparrishgparrish commented on Jun 16, 2025

    @gparrishgparrish

    I had this issue today at work in Firefox 139 in private mode. I was able to complete a couple of traces and received the exports without issue (491KB), then everything after that was all just 1KB files with the null. I had not really made any changes to the extension or had dev tools open at all. I removed and reinstalled the extension and had the same issue, then picked a different option on the export, and it started working again, but after 5-6 exports, it then went back to the 1KB export, and any export changes had no effect. I then opened dev tools and found this error below, in case it is helpful. Also, another weird behavior I noticed is that occasionally my in-private window is just closed by something, my SAML trace window is still up, but the Firefox private window I was using is just gone. I am going to switch over to Chrome to see if the exports work normally there.

    Image

  23. kellenmurphy commented on May 10, 2026

    @kellenmurphy
    Contributor

    The root cause is in enrichWithResponse in SAMLTraceIO.js. When a request is blocked, cancelled, or interrupted before a response arrives, getResponse() returns undefined. That gets passed to createFromJSON, which calls JSON.stringify(undefined) — but JSON.stringify(undefined) doesn't produce a string, it returns the JS value undefined. So JSON.parse throws a SyntaxError, the exception goes uncaught, ui.exportResult is never updated, and the downloaded file contains just null.

    The fix is a one-line null guard at the top of enrichWithResponse: if res is null or undefined, return early. That lets interrupted requests appear in the export without response fields, rather than crashing the whole thing. I'll include this in a PR along with a fix for the related issue in #106.

  24. tvdijen commented on May 31, 2026

    @tvdijen
    Member

    Closed in #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions