Skip to content

Refused to get unsafe header "djdt-store-id" #1647

Closed
@xiongchiamiov

Description

@xiongchiamiov

We're getting instances of this error in the javascript console while using the toolbar in local development.

This stems from a CORS issue where only certain headers are only allowed to be accessed unless whitelisted. In 9973872 this code was added:

    update_on_ajax() {
        const sidebar_url =
            document.getElementById("djDebug").dataset.sidebarUrl;
        const slowjax = debounce(ajax, 200);

        const origOpen = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function () {
            this.addEventListener("load", function () {
                let store_id = this.getResponseHeader("djdt-store-id");
                if (store_id !== null) {
                    store_id = encodeURIComponent(store_id);
                    const dest = `${sidebar_url}?store_id=${store_id}`;
                    slowjax(dest).then(function (data) {
                        replaceToolbarState(store_id, data);
                    });
                }
            });
            origOpen.apply(this, arguments);
        };
    },

Since it's patching XMLHttpRequest.open to attempt to examine all ajax requests, this gets triggered when making requests to things that don't allow djdt-store-id access (and shouldn't, because they're owned by third parties and don't know anything about this tool). This doesn't appear to functionally break anything, but it adds confusing error messages.

I think the answer is to squash the error in this line: let store_id = this.getResponseHeader("djdt-store-id");. It's not clear to me how to do this, though, since the docs don't mention any possibility of this function doing anything other than returning a result or returning null, and my searching only finds discussions of how to fix the problem when you own the other side of the requests or generally actually need to access this header.

(Also kinda sorta related to #1399, which is about documentation of CORS issues.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions