From 1dc07756256c49599e58b4e917312ca0569e6b06 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 14 Mar 2019 21:29:25 -0700 Subject: [PATCH] Update download token generation strategy --- package.json | 1 + src/ui/torrent_details.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index aaefc97..77d1ae8 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "font-awesome-sass-loader": "^2.0.1", "history": "^4.7.2", "isomorphic-fetch": "^2.2.1", + "js-sha1": "^0.6.0", "moment": "^2.20.1", "node-sass": "^4.7.2", "numeral": "^2.0.6", diff --git a/src/ui/torrent_details.js b/src/ui/torrent_details.js index 5978462..db919ad 100644 --- a/src/ui/torrent_details.js +++ b/src/ui/torrent_details.js @@ -14,6 +14,7 @@ import { Input, } from 'reactstrap'; import moment from 'moment'; +import sha1 from 'js-sha1'; import TorrentOptions from './torrent_options'; import TorrentProgress from './torrent_progress'; import ws_send from '../socket'; @@ -28,7 +29,10 @@ import selectTorrent, { import { updateResource } from '../actions/resources'; import { formatBitrate } from '../bitrate'; -const dlURI = (uri, token, id) => `${uri.replace('ws', 'http')}/dl/${id}?token=${encodeURIComponent(token)}`; +const dlURI = (uri, token, id) => { + const dlToken = encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(sha1.arrayBuffer(id + token))))); + return `${uri.replace('ws', 'http')}/dl/${id}?token=${dlToken}`; +}; function basename(path) { const parts = path.split("/");