15 ms·
Password protect a static HTML page
- Retr0id 4y agoFor anyone else wondering what the KDF is, it appears to be PBKDF2 with 1000 iterations: https://github.com/robinmoisson/staticrypt/blob/5dac008ba64490485db9a51b15e6b2f3adb2a145/lib/cryptoEngine/cryptojsEngine.js#LL50C35-L50C41 https://github.com/robinmoisson/staticrypt/blob/5dac008ba644...
- benatkin 4y agoHere's one w/ 100_000. Perhaps it's missing a couple zeroes. https://github.com/yjs/y-webrtc/blob/master/src/crypto.js#L28 https://github.com/yjs/y-webrtc/blob/master/src/crypto.js#L2...
- deleted 4y ago[deleted]
- 8organicbits 4y agoThere was some recent discussion about KDF for password managers. Bitwarden increased rounds from 100k to 600k for new accounts. But keep in mind, in order to get the encrypted store you either need to authenticate online or steal it from a device that previously authenticated. An attacker needs to bruteforce the master password quickly as the stored password are useless if they are changed. There's layers of security and a limited window of opportunity. Here, the encrypted document is encouraged to be hosted publicly. There isn't any authentication before the encrypted document is downloaded. If the document remains sensitive long term, then we need to protect it from attack using computers that will exist >10 years from now. Since this tool doesn't have layered security, and the contents likely remain sensitive long term the single security layer should be stronger. We can hand wave this and say that the user should pick a strong password or only store minimally sensitive documents but most won't and there's nothing here to inform or encourage them to do so. (Even single character passwords are allowed...)
- superkuh 4y agoIf you have to run javascript it is not a static page anymore. I've seen a lot of this particularly weird overloading of "static HTML" lately. Static HTML, or static webpage, is meant to describe the experience from the person who is trying to look at the page. It does not describe the experience of the dev. Using a dynamic script or application to generate a static html page that requires no JS execution is a static page. Using a static HTML page and then hiding it behind javascript execution is explicitly not a static HTML page. Use .htaccess. And if you can't, reconsider the choices you made that restrict your abilities so significantly.
- creatable 4y agoThis is nonsense semantics. Words and phrases change meaning over time.
- scarface74 4y agoIt didn’t even “change meaning” As far back as I remember (and I played with JavaScript when it was first introduced in beta for Netscape), a “static web page server” always meant that there was no backend server generating pages on the fly.
- cubefox 4y agoI would call any server side or client side code which alters the HTML non-static. A static HTML page is just an HTML file which is stored on the server and displayed as-is in the browser.
- superkuh 4y agoExactly. I don't know where the confusion is, but I'm saying that it doesn't matter how the page is generated. It is sent to the website visitor as just HTML. When the user views it it is all there, just html. No changes. For example, I have a perl script that generates a set of .html files every night to show new additions to my library. They are static .html files on disk and never modified before the user views them. Just because a perl script (not connected to the web server in any way) made it does not "taint" the HTML so it is not static. The program, or the person, that wrote the HTML does not matter. All that matters is that it's just static unchanging HTML.
- deleted 4y ago[deleted]
- pier25 4y agoAnyone remembers .htaccess files from Apache? Good times.
- johannes1234321 4y agoThose would be quite nice, if web browsers were good HTTP clients. The user experience with basic auth is not so good. The dialogs give little way to customize and providing information for user. No support for logout or any form of password changes.
- marginalia_nu 4y agoIsn't that sort of a feature? Customizable HTTP auth dialogs are a security liability, as they blur the line between content and browser.
- johannes1234321 4y agoYes and no. There is some part of it which helps to identify where you are connecting to. Meanwhile those dialogs aren't modal anymore, which allows access to https certificate info, but it is still complicated to provide trust for average users.
- tqkxzugoaupvwqr 4y agoLogout is possible: The server has to send http status 401 if I recall correctly. The browser treats this as logout.
- johannes1234321 4y agoThis requires some server side handling. The web browser could have a logout button so I can end my session. Probably that should be combined with a configured target page for the user. And well, my experience there is about 20 years old, but back then sending 401 wasn't enough. You had to send a different auth request, which then would pop up a new password dialog first. Indoubt 401 is enough today as well, as the browser can't distinguish whether a specific resource is restricted or whether the whole session should be invalidated.
- jrexilius 4y agoThis is a great utility and has a lot of meaningful use-cases. Thanks for puting this out there!
- Karellen 4y agoOr... http authentication.
- edent 4y agoHow do you use that on something like GitHub pages?
- marginalia_nu 4y agoTurns out when you give up the work of hosting your up stuff, you also give up some of the benefits from doing so.
- forrestthewoods 4y agoWhich is why a project that returns some of those benefits is genuinely cool and useful.
- johannes1234321 4y agoAnd even can give benefits by storing it encrypted at rest.
- Dma54rhs 4y agoYou can email or hand out physical copies on usb would be one use case where server auth can't compete.
- Karellen 4y agoAren't existing encryption tools more flexible for sending out copies via those methods? e.g. by making more cipher suites available? Or by allowing you to encrypt with the intended recipients' public keys, so you don't need to worry about distributing the passphrase securely? And might allow better integration with password managers, as the OS would recognise the files as being encrypted?
- fabiensanglard 4y agoA more lightweight solution would be to hash the password and have a copy of that file at this url. windows.location = hash(password);
- pdq 4y agoClient side decryption has the benefit that no machine or router in the middle can view or cache the decrypted page without the password.
- tptacek 4y agoYou mean, unless they tamper with the Javascript to capture the password (or the derived key).
- dividuum 4y agoI designed a similar tool with that threat model in mind: the resulting HTML/JS is as minimal as possible so it’s possible to inspect before entering the password. Of course assumes safe browser and client machine.. https://github.com/dividuum/html-vault https://github.com/dividuum/html-vault
- viraptor 4y agoKind of possible. With enough content, would you actually spot a "}; and some highly obfuscated code in the middle of the blob? (My guess is a no)
- dividuum 4y agoYou're right. Probably not. But at least the chance exists as there isn't a multi-KB obfuscated JS dependency somewhere that would be a lot harder to handle.
- efreak 4y agoValid if you actually host the file online. Local files are generally not allowed to make requests. Not sure if local storage methods are usable without http/s.
- bitexploder 4y agoThe use case for a document like this is a little different from .htaccess. This is something you can share, email, host, etc and have some security in transit and at rest. Yes, .htaccess password protects on the web server, but that is one specific use case and requires a lot of machinery and specific environment. JavaScript is everywhere. And this is a static HTML document in the sense that there is no server side rendering.
- ipaddr 4y agoWhy not use a password protected word document if those are your use-cases?
- creata 4y agoYou definitely could. But I think there are more computers with web browsers than there are computers that can read encrypted Microsoft Word documents.
- yyyk 4y agoOn client systems, PDF readers are as ubiquitous as browsers. An encrypted PDF should do the job better than Word.
- bitexploder 4y agoSimilar use case. I would not use this for anything important. If you just want to shuffle data around with something similar just use something like KeePassX, lets you attach files. Much more configurable with regards to KDF parameters and such.
- fluidcruft 4y agoBut doesn't Word use CBC? Apparently from upthread that's E_ALWAYS_BAD.
- bitexploder 4y agoAhh, well, this is actually a field where I know a lot. Since it is my job. Let me distill up thread. 1. Don’t implement the underlying crypto yourself 2. CBC is hard to get right 3. There are a lot of esoteric attacks and if you have a nation state attacking you they could exploit them, but they won’t because they will just put some crap on your systems and do it easier. Also this is a very simple use case to get authenticated CBC correct with. So, the real answer is “don’t do this, but it is probably okay in this one use case, assuming they didn’t implement all of this themselves (e.g the crypto algorithms themselves) You should still listen to tptacek though. Use an authenticated crypto mode :)
- realPubkey 4y agoShould have used the WebCrypto API instead of the crypto-js npm package. https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_...
- iamben 4y agoI spent some time Googling this about 6 months ago. Lots of tutorials on Crypto-js, not so many (and almost zero "here's a super simple implementation") for WebCrypto API. I can understand if this is a hobby project why you'd lean into one rather than the other, I probably would have done the same.
- cgb223 4y agoSounds like a golden opportunity for someone with a developer blog to make useful content
- trusz 4y agoNot going to pretend that I know what the most of the stuff mean, or if it is even safe enough, but I've followed the MDN articles and put together this TypeScript snippet [1]. Maybe somebody could comment on it? Also sorry for the long link. Is there any accepted way to post a shorted URL? Edit: added a corrected version [2] [1]: https://www.typescriptlang.org/play?#code/DYUwLgBAbiDGYHsBOEC8EDuBLAdgEwQwDpYkBPAB0SIHNwAlAQ3wQFsA1R4AVxAGcAFDhAYIAVVxgAHAEEkSRmQEBGAGwBKdQG4AUHsZ8yOWBABm3Y2CwIcEEMfJUAKgAt7AETiOwAvl-AAsvx8jHQAXHxgSLg0ADQQFAZ8GMh4YRCR0Tg0EOrpAApIbFh+ADwA2pkx8TjcrABGIEgAugB8EADeehA9EAD0fTq9-X0QhSAUQ70DUz2wNpEQANYgZGgQjBiMWJB0wgpgIADSqwBiRaz5SSlIeAKJfMmp6t3Tg8MDEACiDpRWNjRZiMgfMcIt7KQ-iA8EFHqEQOtNttIBDvLCQnQBCsyPE-KRAsF4doQQsUb9Dnh3IwwIx1sJRBIcNI5AolKioTDCXRtCMIKUALQZex4CBgFwlV49Ab8mX8oEzD6jTyQqjy95vUGLPBeDmIrY7CDalVgdHwrGreLsqjQ03cklgyBG7zQvXIw06qi2kDmnF2cnQqk0l7DTWOj0UwO09D08SSWTyRQCJ0c4kh0nu43QpwgAAekHQoJgSDALMUACFuKZTE1EABlKI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4WMqC0ELEwHhfDHIxJ5hsc2ChTG6MIBsDwaAHwVhkqoRMhTpDFIETzToHQuhRJKQzBpQ4ZJ1nzOHIomBnK6BtDWaAQlh6hUpAAK2QE0XRQIXgYEQO4l4wzywHVkAIbhuBnGPl4UyB6YRwDCH8eABJBysCbLbLaDWD0inRNiS8tp0TdCvL6TzACsNKAKAernHQHBbkpLSUSc8igUZvLKQ9RwYwxAzXBakr4+5QDFB+R0y2-ygKUAfDeehIBGk1lgFWNuYTWEyGHkAA https://www.typescriptlang.org/play?#code/FAiGGcE8DsGMAIBmBX...
- deleted 4y ago[deleted]
- charles_f 4y agoShameless plug, I did something similar in a markdown processor (which processes any folder with some markdown into an html website). You can either protect some of the pages, or the entire thing https://github.com/cfe84/plaf https://github.com/cfe84/plaf
- Xeoncross 4y agoI'm not a cryptographer, but I'm pretty sure that CBC (https://github.com/robinmoisson/staticrypt/blob/main/lib/cryptoEngine/cryptojsEngine.js#L13 https://github.com/robinmoisson/staticrypt/blob/main/lib/cry...) should be replaced with GCM (https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#aes-gcm_2 https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt...) since this is not a stream. https://security.stackexchange.com/questions/184305/why-would-i-ever-use-aes-256-cbc-if-aes-256-gcm-is-more-secure https://security.stackexchange.com/questions/184305/why-woul... (also, use the built-in WebCrypto API instead of the crypto-js package)
- pluc 4y agoLeave it to full-stack devs to take care of cryptography
- bloqs 4y agoAs a newer dev later in life, I love to learn about inter-disciplinary snobbery/riffing. I learned some of what I know from a full stack dev, who was convinced anyone who couldnt do everything "was shit" and "should be something easier like a web developer or IT guy" instead. I'm excited to learn that pure disciplines also look down on full stack devs
- Smar 4y agoThere is tons of different types of programming out there.
- dragontamer 4y agoCBC is far easier to implement than GCM mode. I bet that most programmers cannot implement a Galois Field in Javascript. Meanwhile, CBC is just "encrypt then xor".
- tptacek 4y agoNobody implements GCM themselves; they get it from a library. CBC, implemented the way you're describing, is almost always insecure.
- Yenrabbit 4y agoDoes anyone know of a way to do something like this but with OAuth? E.g. log in with GitHub to view these docs.
- denysvitali 4y agoI'd say it's not possible in pure HTML + JS (as in, encryption/ access control performed entirely there). The solution (with a server) is: https://oauth2-proxy.github.io/oauth2-proxy/ https://oauth2-proxy.github.io/oauth2-proxy/
- superkuh 4y ago[flagged]
- minusf 4y agofunnily enough in certain circles "static pages" rather mean "static on server side" but "dynamic on client side".
- tptacek 4y agoIf that's wrong, so is the name of every "static site generator". Also: please don't make the same point in two separate top-level comments.
- superkuh 4y agoA static site generator can be used to create an .html file that's dependent on the user to execute a javscript web application to show the content. That makes that generated page dynamic. It doesn't change the nature of the static site generator.
- moondev 4y agoWhat if the user uses curl to view the page. Is it now static?
- superkuh 4y agoThat depends entirely on the page. Does it require javascript execution so that the contents are there? Then it's not. If you can open the file and read the text and see the URLs, yes. But if the page was generated by a script without it ever being a file on the webserver's disk, no.
- tantalor 4y agoThe js is static too
- deleted 4y ago[deleted]
- VoidWhisperer 4y agoThe downside to this method is that since the resulting cryptographic hash and salt have to be in the resulting file, so there is nothing stopping someone from pulling the hash/salt out and bruteforcing it locally (as opposed to being able to ratelimit login attempts on a server) if they are so inclined and have the required resources.. which may not be that much in the way of resources as the tool uses 1000 iterations of PBKDF2[1]. This is magnitudes lower than what OWASP recommends[2]. I wouldn't personally put anything you want secure behind this. [1]: https://github.com/robinmoisson/staticrypt/blob/5dac008ba64490485db9a51b15e6b2f3adb2a145/lib/cryptoEngine/cryptojsEngine.js#LL50C35-L50C41 https://github.com/robinmoisson/staticrypt/blob/5dac008ba644... [2]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2 https://cheatsheetseries.owasp.org/cheatsheets/Password_Stor...
- deleted 4y ago[deleted]
- 411111111111111 4y agoThe linked readme agrees with that https://github.com/robinmoisson/staticrypt#is-it-secure https://github.com/robinmoisson/staticrypt#is-it-secure
- tialaramex 4y agoRight but all that's happening here is stretching. So the difference only matters in the middle. Regardless of the strategy bad guys will guess "1234" or "sesame" (too easy) and they won't guess a random 128-bit key I just generated with my hexadecimal dice (impossible). This weakness only means it's easier than expected to guess your password is "suckitelon" or "GoCowboys1978" or whatever We put a lot of effort into teaching people to do better stretching, but it feels like the result was they put even more passwords on things, rather than using the breathing room to get off passwords. If your project for 2023 is "Use a fancier password hash" instead of "Get rid of passwords" you are Doing It Wrong™. If you wanted to do something like this seriously, consider hmac-secret extension to FIDO, which means Security Keys (so the things you'd use to log in to say Google or Facebook) can present an arbitrary always-identical secret value which would be more than adequate to secure such a thing unlike a human memorable password. Today hmac-secret is mostly used to authenticate to an off-line laptop PC or similar.
- anurag 4y agoPagecrypt does the same thing, but with the Web Crypto API. More (including a sample repo) at https://render.com/blog/static-site-auth-pagecrypt https://render.com/blog/static-site-auth-pagecrypt.
- sowbug 4y agoSimilar here: https://github.com/sowbug/quaid https://github.com/sowbug/quaid It works with a GPG-encrypted file. I figured that was safer than developing my own encryption format. As it is, any vulnerability in the decryption process is equivalent to a vulnerability in GPG.
- k3vinw 4y agoThanks for creating this. I was just thinking why not use gpg for this?
- victorbjorklund 4y agoWow. This is really cool. I wonder if it would be possible to kind of build a site with personal pages etc for different user each encrypted by their own password Like domain.com/user1 and domain.com/user2 each are encrypted but with their own passwords. So user 1 can only visit his own page and not other users. (I know there would be much easier to just do a traditional webapp but as a concept it is super cool).
- efrecon 4y agoI am using it in exactly that context and it is good enough for the level of security I need to achieve. I understand this can be brute forced, but this is a risk I am willing to take given the level of "secrecy" of the content.
- CM30 4y agoOh neat, this is a neat concept. Always wanted a secure way to password protect a page without server side coding, and this is definitely the closest we've gotten in years. Not sure I'd trust it myself, but it definitely seems like a good option for those with limited hosting options (like GitHub pages or Neocities) and a need to secure some content.
- maxlaumeister 4y agoI'm going to plug my project PageCrypt here too, which predates StatiCrypt, has a web UI that's good for one-off page encryption, and does use the WebCrypto API. https://github.com/MaxLaumeister/pagecrypt https://github.com/MaxLaumeister/pagecrypt https://www.maxlaumeister.com/pagecrypt/ https://www.maxlaumeister.com/pagecrypt/
- hiAndrewQuinn 4y agoPageCrypt is excellent. I wrote a tutorial a while back on Reddit about how to use it for password-protected Anki cards. Just to give that extra layer of security.
- yoble 4y agoYep, looks great! If I had known about it at the time I might not have written StatiCrypt. I added it to the "Alternatives to StatiCrypt"[1] section of the Readme years ago when I discovered it :) [1] https://github.com/robinmoisson/staticrypt#alternatives-to-staticrypt https://github.com/robinmoisson/staticrypt#alternatives-to-s...
- DanielBMarkham 4y agoGad! I have spent all morning trying to --- password protect a static html page. How in the hell does HN have a story about the exact topic I've been struggling with appear just a dozen or so hours after I started working on it. Wow. I was _extremely_ happy to see this posted. However when I click the link I am taken to the library I had initially tried and had to reject. Without getting into the crypto side of things (which very well may resolve to "just make it tough enough for most folks") I crashed and burned using this tool once my page reached certain sizes. (I was cramming everything I needed into one page and I had a big hunk of bytes that I didn't want hanging out on the filesystem) As I understand it, this is a known issue in V8. V8 limits the number of properties/collection members an object can have. There's a flag you can use with node to get a little more headspace, I believe it's something like "--max-old-space-size=8192" but it's a V8 problem, not a node problem. The staticrypt coders could also switch to a streaming cryptography instead of block, but that's far too much to ask of the casual user who only wants to lock up a page or two. This is a really cool tool, and I wished I could have used it. Good luck to the team going forward. I've gotta find something else as this doesn't work for me.
- snowstormsun 4y agoSomething similar has been posted before some time ago: https://news.ycombinator.com/item?id=34083366 https://news.ycombinator.com/item?id=34083366
- doodlesdev 4y agoWhich in turn has inspired the creation of PrivacyProtect [0]. It allows to do basically the same thing as the other applications, but in my opinion the interface is better, it also allows you to directly select a file which I guess is easier than copying the contents, it also means you can just select an image file for instance or some other type of file other than a web page. [0]: https://www.privacyprotect.dev/ https://www.privacyprotect.dev/
- DanielBMarkham 4y agoWhy is everybody forcing me to upload to the web the very files I want to keep private to myself? If any code in the universe should run locally, it's this kind of code. I don't get it. Great UI, though. But I still don't get it.
- snake_doc 4y agoSimilar to portable-secret? https://github.com/mprimi/portable-secret https://github.com/mprimi/portable-secret
- adamcharnock 4y agoI saw a super simple example of this back in the 90s when I was first leaning web development (was in Web Development for Dummies or some such). The page prompted the user for the password, and then used the password to generate the URL for the hidden page and redirected the user there. Of course this wasn’t over HTTPS, and you got a 404 if you entered the wrong password, but it was still a neat hobbyist trick for the era. I think the author even wagered that readers couldn’t defeat it.
- aflag 4y agoThat was very popular back then. Besides the 404, it has the side effect that if that URL leaked, then your password system broke. With this implementation leaking the page is not a big deal (assuming you're not using it to store state secrets or anything like that)
- eduction 4y agoTake one shot if you thought this was going to be about .htaccess and a second if you’re confused why it wasn’t.
- eduction 4y agoHey look it’s a “static” HTML file that decrypts itself using AES 256 CBC. Sure, that sounds static and simple and good for the web. What could go wrong. Some obvious limitations: -requires users to re-authenticate for every protected file on your site -assets loaded by the page not password protected -uses a single password globally shared by everyone who wants to read the doc -archiving the page itself is useless unless you also archive the password, which must be done out of band -this doesn’t compose or integrate with the web: none of the common tools you would use to download, spider, archive, spindle, mutilate web pages know how to deal with this It’s certainly one solution. The http basic auth built into every popular webserver is another, with none of the above limitations. But I guess that would require spending 5 minutes learning and implementing some server config, and why do that when you can further ruin the web by shoving yet more user hostile complexity into client side JavaScript. Sorry to sound bitter I just feel this is a really bad idea if you think about it for any length of time.
- dakiol 4y ago> The http basic auth built into every popular webserver is another, with none of the above limitations. The obvious advantage of OP's approach is that one doesn't need to control the server that serves the HTML (e.g., static site served via GitHub pages would be enough)
- lalopalota 4y agoOn the web, all pages on a domain can be encrypted with the same password. If the user selects the "remember me" checkbox, they won't have to authenticate on each page. This also works without a webserver. It can be a local file that is opened in a browser.
- NKosmatos 4y agoI came here for the comments and sure enough I wasn’t disappointed :-)
- ebfe1 4y agoHah! I did a similar thing for a fun friday afternoon security challenge with AES256 encryption on static website using the answer to challenges as the key here if anyone wanna play with it... :) https://challenge.surge.sh/ https://challenge.surge.sh/ It should take you no less than 10 minutes ;)
- worldsavior 4y agoThe title is a bit misleading. The title implies ONLY HTML when it uses some JS. I guess it's not possible (in anyway I know) without some JS, but still.
- deleted 4y ago[deleted]
- avip3d 4y agoWouldn't .htaccess solve this issue?
- bertman 4y agoNo, this is strictly client-side, ie. encryption and decryption happen in the user's browser.
- lalopalota 4y agoThis doesn't require a web server - it works for files opened locally as well.
- ipaddr 4y agoUse apache to serve your page and htpasswd to provide basic authentication. Easy 1994 answer
- Gordonjcp 4y agoI thought that too, but this appears like it works to password protect an html file that's *not* being served off a server. This ought to work with a file on disk too.
- userbinator 4y agoThe more general solution is to use a password-protected archive.
- doodlesdev 4y agoBut then it's not self contained and every time you want to access the archive you also need a program that can decrypt/encrypt that format. Using a self-contained HTML file means it's currently the most portable way to encrypt something and have it available anywhere you can get the file on. By the way, I don't advocate for this idea. But still, I find it a pretty ingenious way to store encrypted data portably. Essentially what is happening is the file contains the encrypted data and the algorithm to decrypt it with the correct passphrase/key.
- chii 4y ago> you also need a program that can decrypt/encrypt that format that's just a self-extracting archive, which is a very common idea and easily created as well (very popular with both shareware distribution). The problem is that you have to trust the extracting code to not install anything else malicious. The browser provides the perfect sandbox - you cannot install malware into the system via javascript in the browser, and thus you can trust it to run.
- efreak 4y ago
- danShumway 4y agoHah, this is another thing I've been thinking about recently :) It's cool to see tools like this popping up. An approach I've played around with, but never sat down to actually build, was to use service workers to be able to encrypt large sites -- the entire site would be encrypted locally from the command line using libsodium's `crypto_secretbox_easy`[0], and all of the data would be concatenated into a series of padded files to try and somewhat hide the number of files/size of the site. That key would be merged with a lookup table that would also be encrypted with a separate key, that would be stuck in the url hash. Then once the site was decrypted (ie, the secretbox key was sent to the service worker from the url) the service worker would intercept any requests the the front-end made and decrypt the original map that would tell it which file chunks to fetch, and then it would decrypt them on the fly and cache them for the duration of the session. Whenever you updated the site, the files would be re-encrypted with another key, but the "user facing" key in the URL would stay the same. The linked project (and other projects people have linked) are a lot more portable, but I was thinking less about being able to have a single file that I carried around and more about being able to put up a full website where I could have something approximating user accounts (ie, possibly having multiple lookup tables that could be decrypted separately per-user), and where I could build full-featured projects that could fetch their own resources. But, I haven't ever gotten around to actually building it, I only ever built some tests to make sure that it would technically work, and I got nervous about rolling my own solution even though I was just going through the libsodium APIs. ---- [0]: I've seen a couple of people recommend using Web Crypto instead, which I've avoided because I thought libsodium ported to the browser was harder to shoot myself in the foot with; is that a bad instinct?
- userbinator 4y agoI'll echo the other sentiments here that I wouldn't consider this "static HTML", and I was expecting something about .htaccess. That said, this seems to be a strengthening of what used to be somewhat common "protection", namely variations consisting of: - Password in plaintext in the source e.g. "if(password=='hunter2') ..." - No correlation between password and page contents (either the content is merely hidden and shown when the password check succeeds, or lightly obfuscated/encrypted using key independent of knowing the password) - Hiding content by using "display:none" or similar
- chii 4y ago> I wouldn't consider this "static HTML" why not? this could be served on a server which does not have any dynamic execution capabilities, and does not require the server to handle any other request other than just the HTML.
- userbinator 4y agoIn my experience, that's normally called "static hosting", not "static HTML".
- VincentEvans 4y agoCan someone explain a bit more how “remember me” works? If symmetric encryption requires a “key” to decrypt - one might expect that you will need to store that key to auto-decrypt. But here it claims that the key is stored salted and hashed. But to auto-decrypt - you need to reverse that salt and hash because you need that key back. How would that work?
- SamBam 4y agoThe passphrase+salt get hashed. This hashed-passphrase is what decrypts the file. You can store the hashed-passphrase in local storage. This means you can auto-decrypt again. You don't need the original passphrase. If bad guys get your computer, they can read the file. However, they cannot trivially work out what your original passphrase was, so it protects you a little if you reused your passphrase elsewhere.
- VincentEvans 4y agoThanks!
- garrison 4y agoMy recent solution to this problem -- for an entire static site -- was to use HTTP Basic authentication with CloudFlare Pages: https://github.com/garrison/cloudflare-pages-shared-password https://github.com/garrison/cloudflare-pages-shared-password
- deaddodo 4y agoI was digging through the comments for someone to point this out. I’m honestly curious why people are using these overly complex options when a solution has been built into the HTTP standard for decades (and, in fact, is heavily abused for many APIs). And it’s superior in many ways, since the file is never delivered until authentication has been completed.
- chii 4y agowith basic authentication, you cannot embed the decryption key into the url via a hash fragment. This means you must have a secondary channel to communicate to the user about the password, and the server must also know the password. So depending on your use-case, the basic auth isn't suitable. For example, mega : https://en.wikipedia.org/wiki/Mega_(service) https://en.wikipedia.org/wiki/Mega_(service) , in which you want to ensure that the decrypted data is _not_ accessible to the server, so the key is not stored nor sent to the server!
- rvnx 4y agoIn a real-life scenario, the server can access the key and collect it back (just farming location.hash)
- deaddodo 4y agoSure you can, it’s been built-in to the HTTP spec since RFC1738[1]. You just do: //<user>:<pass>@<url>[:<port>][/<location>]/ It doesn’t work on IE classic, but should still be perfectly valid on Chrome, Safari, Firefox, etc. 1 - https://www.ietf.org/rfc/rfc1738.txt https://www.ietf.org/rfc/rfc1738.txt
- 4y ago
- inssein 4y agoI just finished building a similar tool: https://utiliti.dev/private-note/ https://utiliti.dev/private-note/ Currently it’s just for plaintext, but might allow for more complex things like the website. The password is stored in the url after the # so it’s never sent to the server. I was going to post this project after I build some more utilities.
- qingdao99 4y agoIs the note supposed to self-destruct even when it's attempted to be opened with incorrect data in the URL hash? (so it hasn't actually been read yet)
- inssein 4y agoToday it does, but might need to find a way around it.
- megous 4y agoIt will leak all over browser's history, though.
- inssein 4y agoIs this a problem? It will only leak on the sender and receivers browser history.
- alpenbazi 4y agowhy reinventing the wheel? .htacess and others
- bawolff 4y agoNo discussion of what KDF is used on the readme page is a giant red flag. Whether using pbkdf2, argon2 or something else, along with what the work factor is, is critical to security in this application.
- dav1app 4y agoI have a similar project called Sasha.html. https://github.com/dav1app/sasha.html https://github.com/dav1app/sasha.html The idea is to export any file as an HTML file with the data as an encrypted string hard coded within the HTML. This way, no specific software is required to decrypt the file, just open it on the browser, type the password and download or view your file. I built this to have a easy way to send encrypted files to any device and open it without having to install external tools.
- tough 4y agoHTTP Basic Auth is a few headers away. I just configured it in my CapRover instance for a deployed app to have my db GUI
- t2hv33 4y agoOk
- quickthrower2 4y agoThere is a difference between this kind of password and the password for a server. With the OP system the attacker gets potentially way more attempts to access the page and gets to try in the future with whatever tech comes out. On the plus side it is E2E encrypted! With a traditional server they can rate limit attempts on the password. But they probably don’t encrypt it using YOUR password (unless it is a password manager etc.) so an attacker could get the plaintext if there is a breach.
- _8j50 4y agoPhishing attachments/links abuse tools like this FYI, not impugning it in the least bit though. It deters automated sandbox analysis by asking the user to use a password in the email body. For zip,pdf,etc... you can easily tell when they're encrypted and block/alert on them but not so with non-standard methods like this.
- gildas 4y agoYou can do the same thing with SingleFileZ [1] which can protect saved pages with a password. It relies on the zip specification to store the encrypted resources (html, images, css, etc.). Here's an example of protected page saved with SingleFileZ: https://gildas-lormeau.github.io/private/ https://gildas-lormeau.github.io/private/ (password: thisisapage) [1] https://github.com/gildas-lormeau/SingleFileZ https://github.com/gildas-lormeau/SingleFileZ
- Jamie9912 4y agoRequirement of npm for this? No thank you
- nailer 4y ago> StatiCrypt uses the crypto-js library to generate a static, password protected page that can be decrypted in-browser. Bad idea. Your browser comes with web crypto, including AES256 and PBKDF2. See MDN.
- hannasm 4y agoWhy not use WebCrypto?
- chanux 4y agoDoes anyone know a 'simple enough' way of placing a static site behind an auth wall (say, oAuth)? Just today I wrote down about what I use https://chanux.me/blog/post/static-site-with-auth/ https://chanux.me/blog/post/static-site-with-auth/ I note down two other possible methods in the post. Would love to hear about more info.
- lvice 4y agoAzure App Service provides an integrated optional auth wall for the apps deployed, without adding extra code. It may be a bit overkill to deploy a static site on the App Service, but it's supported. See here: https://learn.microsoft.com/en-us/azure/app-service/overview-authentication-authorization https://learn.microsoft.com/en-us/azure/app-service/overview...
- nstart 4y agoThe bank I use recently switched to using a similar method for sending their statements. The html page they send via email is password protected. I dig into how they do it (also to ensure they aren’t phoning anywhere when I open the report) and they encrypt the report content using a similar method to the one shared here. It’s neat and I have to give them kudos for doing something neat like that as opposed to sending a pdf with a password on it. Why html though? They do have some js and interactive functionality in there. I can slice and dice my monthly report within the single html page they send which is actually quite handy (and there’s the default “show me my transactions in a list with opening and closing balance” option as well).
- LeonidBugaev 4y agoI had more simple and dumb approach in past. Lets say you have some password like "super-secret". Just place a secret "html" with content under the directory with the same name as your password. In public page have some prompt with password. When user enter password, you either redirect, dynamically inject iframe with your page. Since there is no way to list files/dirs of http server, it does pretty good job.
- londons_explore 4y agoI wouldn't consider that awfully secure... Your local browser will be saving your 'password' unencrypted in the cache and history, and maybe syncing to other devices. Any workplace security system will probably be keeping records of your 'password'. Any mistake on the web server could turn on directory listing, revealing the password. Some other user of the web server, even a sandboxed low privilege process, will often have the ability to list directories.
- t312227 4y agohmmm ... let me google that for you: "The 'Basic' HTTP Authentication Scheme" * https://www.rfc-editor.org/rfc/rfc7617 https://www.rfc-editor.org/rfc/rfc7617 or * https://en.wikipedia.org/wiki/Basic_access_authentication https://en.wikipedia.org/wiki/Basic_access_authentication
- deleted 4y ago[deleted]
- japanman425 4y ago[dead]
- deleted 4y ago[deleted]
- diceduckmonk 4y agoPeople might also be interested in self-contained Wikis https://en.wikipedia.org/wiki/TiddlyWiki https://en.wikipedia.org/wiki/TiddlyWiki
- diceduckmonk 4y agoIf this can be repurposed to just password protect a specific section of a page, then can it be repurposed to decrypt JavaScript embedded/encrypted in that section performs an "authenticated" API calls. This could be useful if you want to allow making edits and publishing this to a server, but keep authentication entirely client-side.
- wardpearce 4y agouses cryptojs
- yoble 4y agoHi HN! Author of the tool here. Just woke up to a few emails pointing me to this thread. Thanks for the interest and added eyeballs! I'll answer some of the comments here and address the newly opened issues during the day. To answer a few questions that seem common skimming this thread: * CBC vs GCM: we had a conversation regarding this topic where it seemed CBC weaknesses do not apply in StatiCrypt context. I'd love to hear your thoughts if you have any - issue is here[1]. * WebCrypto: I've been wanting to use WebCrypto instead of crypto-js for years now. It's been in my "Important but not urgent" bucket (since crypto-js should be secure too), the interface is different so I want to make sure I do it correctly and life happened, so I never got farther than drafts. Thank you for the PRs, I hope to get to it soon! * "static" means no server-side logic (not no JS): I first made StatiCrypt to solve my own issue of wanting to password protect an html page I could host on a static file host (Netlify, Github pages...). The whole point is to not have a server or DB, so we can't use Basic auth etc. * Iteration count for PBKDF2: will increase today As I write in the FAQ[2] I do my best to implement things correctly but I'm not a cryptographer - any feedback to make the tool better or more secure is very welcome! [1] https://github.com/robinmoisson/staticrypt/issues/19#issuecomment-1322389267 https://github.com/robinmoisson/staticrypt/issues/19#issueco... [2] https://github.com/robinmoisson/staticrypt#is-it-secure https://github.com/robinmoisson/staticrypt#is-it-secure
- deleted 4y ago[deleted]
- mov_eax_ecx 4y agoIt IS a bad idea. 1) The attacker get access to the server and changes the file on the server, one that writes an html/js that redirects to https://example.com/malicious.html https://example.com/malicious.html with the same interface and captures your secret password. Proceeds to access your file with your password. 2) The code calls back home in xhr.open('POST', 'https://zlgpaemmniviswibzuwt.supabase.co/rest/v1/rpc/increme https://zlgpaemmniviswibzuwt.supabase.co/rest/v1/rpc/increme...', true); i don't want YOU to know when i open a file, or encrypt a file. 3) The surface attack of the browser is HUGE, there are many escape the sandbox vulns, same origin bypass, zero day exploits that can be exploited, take a look at the cve database of chromium, using the browser the way it is proposed is a big mistake. Finally, the code is not audited, may have cryptographic weakness as pointed in other comments. The solution you made could be good for a class assignment, or to learn how to use cryptojs, but from the security standpoint is a mistake to use it for anything serious. If you are security conscious, you should use VeraCrypt/bitlocker, a simple rar/zip with password, even a pdf/.docx with password, or use a secure server with SSL, sftp?.
- twodave 4y agoA technique I’ve used in the past is just turn off directory listing and shove protected content behind a directory named using the hash of the password. Then after hashing the password provided by the user, the directory either exists or it doesn’t. Edit: I wouldn’t recommend this for anything serious, but for some blog posts of my wife’s that we wanted to be relatively private, it was good enough.
- chpatrick 4y agoI would just use tweetnacl's secretbox for this instead of custom crypto.
- MasterYoda 4y agoDoes anybody know if image resources also is encrypted or is it just the html content?
- tucif 4y agoI do see this useful in cases where you might want to keep something private from the server-side and are not too concerned about server-side tampering. Then could use basic auth to protect access from outside and a tool like this to protect access from inside.