Skip to content

Commit

Permalink
playground: avoid XSS via external download url
Browse files Browse the repository at this point in the history
Although this is the playground, avoid allowing arbitrary data to be set
in an HTML element. These days we can use `URL()` to parse the
hostname/port/pathname.
  • Loading branch information
jelly authored and martinpitt committed Jun 20, 2023
1 parent 934a4e3 commit 1d03e7d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/playground/speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,11 @@ function download(ev) {

/* Allow use of HTTP URLs */
if (path.value.indexOf("http") === 0) {
const anchor = document.createElement("a");
anchor.href = path.value;
const url = new URL(path.value);
options.payload = "http-stream2";
options.address = anchor.hostname;
options.port = parseInt(anchor.port, 10);
options.path = anchor.pathname;
options.address = url.hostname;
options.port = parseInt(url.port, 10);
options.path = url.pathname;
options.method = "GET";
} else {
options.payload = "fsread1";
Expand Down

0 comments on commit 1d03e7d

Please sign in to comment.