Skip to content

Commit

Permalink
fix(security): remove URL shortener experiment
Browse files Browse the repository at this point in the history
As noted in #305 this introduces confusing UX
and additionally short hashes produced by murmur3
are non-cryptographic and support for it in CIDs
will be removed / blocked in near future
  • Loading branch information
lidel committed Nov 6, 2017
1 parent 2648c22 commit 15e7168
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
4 changes: 0 additions & 4 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
"message": "Upload to IPFS",
"description": "An item in right-click context menu"
},
"contextMenu_createShortUrl": {
"message": "Create Short URL (Experimental)",
"description": "An item in right-click context menu"
},
"notify_addonIssueTitle": {
"message": "IPFS Add-on Issue",
"description": "A title of system notification"
Expand Down
53 changes: 0 additions & 53 deletions add-on/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,64 +419,11 @@ browser.contextMenus.create({
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
onclick: copyAddressAtPublicGw
})
browser.contextMenus.create({
id: contextMenuCreateShortUrl,
title: browser.i18n.getMessage(contextMenuCreateShortUrl),
contexts: ['page', 'image', 'video', 'audio', 'link'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: copyShortAddressAtPublicGw
})

function inFirefox () {
return !!navigator.userAgent.match('Firefox')
}

// URL Shortener
// -------------------------------------------------------------------

async function copyShortAddressAtPublicGw (info) {
let longUrl = await findUrlForContext(info)
if (longUrl.startsWith(state.gwURLString)) {
// normalize local URL to point at the public GW
const rawIpfsAddress = longUrl.replace(/^.+(\/ip(f|n)s\/.+)/, '$1')
longUrl = urlAtPublicGw(rawIpfsAddress)
}
const redirectHtml = `<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<noscript><meta http-equiv='refresh' content='0; URL=${longUrl}' /></noscript>
<title>${longUrl}</title>
</head>
<body onload='window.location.replace("${longUrl}")'>
Redirecting to <a href='${longUrl}'>${longUrl}</a>
`
// console.log('html for redirect', redirectHtml)
const buffer = ipfs.Buffer.from(redirectHtml, 'utf-8')
const opts = {hash: 'murmur3'}
console.log('[ipfs-companion] shortening URL to a MurmurHash3', longUrl)
ipfs.add(buffer, opts, urlShorteningResultHandler)
}

function urlShorteningResultHandler (err, result) {
if (err || !result) {
console.error('ipfs add error', err, result)
notify('notify_uploadErrorTitle', 'notify_inlineErrorMsg', `${err}`)
return
}
result.forEach(function (file) {
if (file && file.hash) {
const path = `/ipfs/${file.hash}`
const shortUrlAtPubGw = urlAtPublicGw(path)
copyTextToClipboard(shortUrlAtPubGw)
notify('notify_copiedPublicURLTitle', shortUrlAtPubGw)
if (state.preloadAtPublicGateway) {
preloadAtPublicGateway(path)
}
}
})
}

function preloadAtPublicGateway (path) {
// asynchronous HTTP HEAD request preloads triggers content without downloading it
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit 15e7168

Please sign in to comment.