-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes window.ipfs is added after page load #368
Merged
lidel
merged 9 commits into
ipfs:master
from
tableflip:fix/window.ipfs-added-after-page-load
Feb 7, 2018
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8b6cc0e
fixes window.ipfs is added after page load
alanshaw 40a9778
removes hats
alanshaw 4604290
removes *.ls from whitelist
alanshaw a2b1377
adds tests for preAcl
alanshaw 6296a78
removes .only
alanshaw 1a968ee
yarn fix: remove dependency on git binary
lidel 0f7503c
uglifies proxy content script and removes unused (inlined) page script
alanshaw 3b4e4f7
Merge branch 'master' into fix/window.ipfs-added-after-page-load
alanshaw e618995
Fix Jenkins by adding git to alpine image
lidel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
'use strict' | ||
|
||
function injectScript (src, target, opts) { | ||
function injectScript (code, opts) { | ||
opts = opts || {} | ||
const doc = opts.document || document | ||
|
||
const scriptTag = doc.createElement('script') | ||
scriptTag.src = src | ||
scriptTag.onload = function () { | ||
this.parentNode.removeChild(this) | ||
} | ||
const scriptTag = document.createElement('script') | ||
scriptTag.innerHTML = code | ||
|
||
target = doc.head || doc.documentElement | ||
const target = opts.target || doc.head || doc.documentElement | ||
target.appendChild(scriptTag) | ||
scriptTag.parentNode.removeChild(scriptTag) | ||
} | ||
|
||
module.exports = injectScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[ | ||
"block.get", | ||
"block.stat", | ||
"dag.get", | ||
"dag.tree", | ||
"dht.get", | ||
"dht.findprovs", | ||
"dht.findpeer", | ||
"dht.query", | ||
"files.cat", | ||
"files.catPullStream", | ||
"files.get", | ||
"files.getReadableStream", | ||
"files.getPullStream", | ||
"object.get", | ||
"object.data", | ||
"object.links", | ||
"object.stat", | ||
"pubsub.subscribe", | ||
"pubsub.unsubscribe", | ||
"pubsub.peers", | ||
"swarm.peers", | ||
"swarm.addrs", | ||
"swarm.localAddrs" | ||
] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const defaultRequestAccess = require('./request-access') | ||
|
||
// This are the function that DO NOT require an allow/deny decision by the user. | ||
// All other IPFS functions require authorization. | ||
const ACL_WHITELIST = Object.freeze(require('./acl-whitelist.json')) | ||
|
||
// Creates a "pre" function that is called prior to calling a real function | ||
// on the IPFS instance. It will throw if access is denied, and ask the user if | ||
// no access decision has been made yet. | ||
function createPreAcl (getState, accessControl, origin, permission, requestAccess = defaultRequestAccess) { | ||
return async (...args) => { | ||
// Check if all access to the IPFS node is disabled | ||
if (!getState().ipfsProxy) throw new Error('User disabled access to IPFS') | ||
|
||
// No need to verify access if permission is on the whitelist | ||
if (ACL_WHITELIST.includes(permission)) return args | ||
|
||
let access = await accessControl.getAccess(origin, permission) | ||
|
||
if (!access) { | ||
const { allow } = await requestAccess(origin, permission) | ||
access = await accessControl.setAccess(origin, permission, allow) | ||
} | ||
|
||
if (!access.allow) throw new Error(`User denied access to ${permission}`) | ||
|
||
return args | ||
} | ||
} | ||
|
||
module.exports = createPreAcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
async function requestAccess (origin, permission) { | ||
const msg = `Allow ${origin} to access ipfs.${permission}?` | ||
|
||
// TODO: add checkbox to allow all for this origin | ||
let allow | ||
|
||
try { | ||
allow = window.confirm(msg) | ||
} catch (err) { | ||
console.warn('Failed to confirm, possibly not supported in this environment', err) | ||
allow = false | ||
} | ||
|
||
return { allow } | ||
} | ||
|
||
module.exports = requestAccess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too permissive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a whitelist right? Any other calls will by default be blocked? Think they are all fine, but I do worry about for example MFS being totally open for everyone with access to window.ipfs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we remove all
*.ls
from whitelist for now. Adding / reading specific hash can be done without explicit permission, but listing internal node states should require explicit confirmation.