-
-
Notifications
You must be signed in to change notification settings - Fork 426
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
Image Uploads #287
base: master
Are you sure you want to change the base?
Image Uploads #287
Conversation
For empty boards, the canvas area is sometimes smaller than the available browser window. We want to be able to drop the image anywhere on the screen.
Thank you very much for contributing this long-requested feature ! I'll try to review it soon, but before:
|
I see there are also still TODOs in the code. Feel free to switch it back to ready for review when you are ready for me to have a look |
server/server.js
Outdated
break; | ||
case "board-assets": | ||
const [, boardId, assetName] = parts; | ||
const file = fs.readFileSync(path.join(config.HISTORY_DIR, `board-${boardId}`, assetName)); |
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.
also, we cannot have blocking code like this in the request handling function
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 can do some more research on this but do you happen to know if calling a function that returns a promise would solve this issue?
Something like this:
async function readFile(request, response) {
// ... create promise, read file from disk, and handle response.
}
function handleRequest(request, response) {
// ... handlers
case 'board-assets':
serveFile(request, response);
break;
// ... other handlers
}
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.
you can look at how it's done in the rest on the code; we use async fs functions
client-data/tools/image/image.js
Outdated
function createImageElement(data) { | ||
var img = svg.getElementById(data.id) || Tools.createSVGElement("image"); | ||
img.setAttribute("id", data.id); | ||
img.setAttribute("href", data.src); |
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 big security vulnerability, isn't it ?
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.
Anyone can send an image event with the src
attribute they want
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.
Is the concern that a user of Board A would be able to load images from Board B (which may be a "private" board)?
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.
The bigger concern is that they may have all users make requests to their own server
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.
Ah OK - so the concern is that an attacker could inject a URL that points to a server that they control, and that serves files with malicious content. Is that right?
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.
Yes, they could serve whatever they want, but also log the ip addresses of everyone connected
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 believe this has been addressed with the latest commit 👍 Let me know if you disagree.
client-data/tools/image/image.js
Outdated
@@ -80,7 +89,7 @@ | |||
function createImageElement(data) { | |||
var img = svg.getElementById(data.id) || Tools.createSVGElement("image"); | |||
img.setAttribute("id", data.id); | |||
img.setAttribute("href", data.src); | |||
img.setAttribute("href", getAbsoluteImageUrl(data.src)); |
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 complicated. Can we remove the src altogether ?
img.setAttribute("href", getAbsoluteImageUrl(data.src)); | |
img.setAttribute("href", "./images/" + data.id); |
that would stress me less :)
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.
How would the browser know where to pull the image to display from?
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.
The browser would make a request to boards/{boardname}/images/{image_id}
, the server would check that the image exists, and if so, serve it.
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.
Yours is a much better approach 😅 This has been updated.
Progress update: I've added some tests but for some reason I can't get them to pass in FireFox (though they pass fine in Chromium). |
Great to see progress ! I don't have a lot of time to spend on wbo at the moment, but I'm determined to merge this once we are confident it works, is secure and maintainable ! |
Description
Drag images (JPG, GIF or PNG) onto the canvas to add them to the whiteboard. Images are saved to disk into a directory with the name name as the board JSON file.
Notable Code Changes
BoardDataList
instead of plain JS object forboards
insockets
module.multiparty
for parsingFormData
on server.TODO
Future Improvements