-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Support of binary attachments #115
Comments
Hmm in theory to have this working…
So to achieve this we would need a new storage format… 🤔
That way we could differentiate between the simple "I'm sharing a secret" and the advanced "I'm sharing structured data" usecase. Reading the file from a HTML File-Select could be done through the FileReader API which gives us an ArrayBuffer
There needs to be some limit of how big the attached files can get in order not to break the storage. Enforcement can be done through the transparent proxy (nginx, …) in front of OTS but the frontend should be able to determine the upload blob size and tell the user "nah mate, don't do that!"… So…
Would need to think about whether the frontend uses the simple format for simple text secrets or always uses the meta format which would always require CLI tooling when fetching from CLI and stop using the simple shell script included in the repo. TL;DR: Sounds like something we could and can implement and I might have a plan… 😅 Code for a test-case to read file through `input`, serialize it and read back for download<html>
<style>
#repr {
font-family: monospace;
white-space: pre-wrap;
}
</style>
<input type="file" id="file">
<div id="repr"></div>
<a href="" download id="lnk">Download</a>
<script>
(() => {
const file = document.querySelector('#file')
const link = document.querySelector('#link')
const repr = document.querySelector('#repr')
/**
* @param {ArrayBuffer} data
* @returns string
*/
function dataToBase64(data) {
return btoa(String.fromCodePoint(...new Uint8Array(data)))
}
/**
* @param {string} encoded
* @returns ArrayBuffer
*/
function base64ToData(encoded) {
const binary = atob(encoded)
return Uint8Array.from(binary, c => c.codePointAt(0)).buffer
}
function updateRepr() {
if (file.files.length < 1) {
repr.innerText = 'WTF? No file.'
return
}
const f = file.files[0]
f.arrayBuffer()
.then(ab => {
const attachmentContent = dataToBase64(ab)
repr.innerText = `
${ab.byteLength}
${JSON.stringify({ attachment: { content: attachmentContent } })}
`
link.setAttribute('href', window.URL.createObjectURL(new Blob([base64ToData(attachmentContent)], { type: 'application/octet-stream' })))
})
}
file.addEventListener('change', updateRepr)
})()
</script>
</html> |
Totally agree with everything you said, and thank you for the very detailed response. I would expect we would need:
I think the addition of an attachment feature is unique as far as OTS to my knowledge. It would be quite useful IMO. Thank you for considering this. |
Hmm not sure that really makes sense: There is no backend to check what has been uploaded as the backend only receives encrypted data. The only way to "limit" this would be to use the I mean yeah, adding that as a string is no pain so should do but that doesn't count as a security feature… 😄 |
I understand, I still think it is useful as a first line of defense (allow list is even better for us). We are restricting the create secret functionality to trusted users via auth anyways. |
I've built the feature in #116 - some screenshots are included. What do you think? |
If you want to test the new feature: It's now active on ots.fyi… |
Works very well. |
I don't get the point here… What popup are you talking about? Clicking the field opens a system file selector (we can't influence in any form)… 🤔
The configuration of the # Define which file types are selectable by the user when uploading
# files to attach. This fuels the `accept` attribute of the file
# select and requires the same format. Pay attention this is not
# suited as a security measure as this is purely a frontend
# implementation and can be circumvented.
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept
acceptedFileTypes: 'image/*,text/*,application/pdf' in order to allow images, text- and PDF-files. (Agreed, configuring this in the public instance probably makes sense to forbid users from posting binaries…) |
Ah saw the screenshot in the PR… …that's indeed system behavior, nothing I built… |
ok, thanks for confirming (1). |
Is it reasonable to consider the possibility to attach binary files to a secret ?
We do have a test case where we need to send PDF files as secrets. I thought it would be interesting to raise that topic.
I did a POC where I did a base64 encoding of a PDF as a secret, and it worked just fine, but I feel a binary attachment would provide a better user experience.
The text was updated successfully, but these errors were encountered: