Skip to content

Commit

Permalink
detect reverse-proxies stripping URL params:
Browse files Browse the repository at this point in the history
if a reverseproxy decides to strip away URL parameters, show an
appropriate error-toast instead of silently entering a bad state

someone on discord ended up in an infinite page-reload loop
since the js would try to recover by fully navigating to the
requested dir if `?ls` failed, which wouldn't do any good anyways
if the dir in question is the initial dir to display
  • Loading branch information
9001 committed Feb 5, 2024
1 parent cab9999 commit 136c0fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions copyparty/web/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5830,7 +5830,7 @@ var treectl = (function () {
var res = JSON.parse(this.responseText);
}
catch (ex) {
return;
return toast.err(30, "bad <code>?tree</code> reply;\nexpected json, got this:\n\n" + esc(this.responseText + ''));
}
rendertree(res, this.ts, this.top, this.dst, this.rst);
}
Expand Down Expand Up @@ -5995,14 +5995,15 @@ var treectl = (function () {
thegrid.setvis(true);
}

r.reqls = function (url, hpush, back) {
r.reqls = function (url, hpush, back, hydrate) {
if (IE && !history.pushState)
return window.location = url;

var xhr = new XHR();
xhr.top = url.split('?')[0];
xhr.back = back
xhr.hpush = hpush;
xhr.hydrate = hydrate;
xhr.ts = Date.now();
xhr.open('GET', xhr.top + '?ls' + (r.dots ? '&dots' : ''), true);
xhr.onload = xhr.onerror = recvls;
Expand Down Expand Up @@ -6049,8 +6050,10 @@ var treectl = (function () {
var res = JSON.parse(this.responseText);
}
catch (ex) {
location = this.top;
return;
if (!this.hydrate)
location = this.top;

return toast.err(30, "bad <code>?ls</code> reply;\nexpected json, got this:\n\n" + esc(this.responseText + ''));
}

if (r.chk_index_html(this.top, res))
Expand Down Expand Up @@ -6272,7 +6275,7 @@ var treectl = (function () {
xhr.send();

r.ls_cb = showfile.addlinks;
return r.reqls(get_evpath(), false);
return r.reqls(get_evpath(), false, undefined, true);
}

var top = get_evpath();
Expand Down
2 changes: 2 additions & 0 deletions copyparty/web/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,8 @@ var toast = (function () {
};

r.show = function (cl, sec, txt, tag) {
txt = (txt + '').slice(0, 16384);

var same = r.visible && txt == r.p_txt && r.p_sec == sec,
delta = Date.now() - r.p_t;

Expand Down

0 comments on commit 136c0fd

Please sign in to comment.