How to get and apply current page query parameters from current AJAX request
No, HTTP_REFERER is not reliable and yes, the solution is to add the query parameters of the current request to each AJAX link. Form API does the same for form elements:

RenderElement::preRenderAjaxForm:

    // Add all the current query parameters in order to ensure that we build
    // the same form on the AJAX POST requests. For example,
    // \Drupal\user\AccountForm takes query parameters into account in order
    // to hide the password field dynamically.
    $settings['options']['query'] += \Drupal::request()-&gt;query-&gt;all();