Live data from Hacker News

Password protect a static HTML page

github.com

261–270 of 294 posts

Re: Password protect a static HTML page

#261
post #54

Earlier quoted context omitted.

Oh, so when I make an .html file in Dreamweaver WYSIWYG HTML editor and save the .html file to my websever ~/www/ dir it is automatically not a static page anymore because I used a program to generate it? This is a very wild and weird interpretation of 'static site' that does not fit with existing usage.

You are the last person to have a say in that considering your incorrect take that JS can't be static. You're clearly misaligned with common usage of terms.

When javascript started being able to change HTML significantly the result was literally named "Dynamic HTML". So it is clear this is not a static HTML page. The only thing left to argue is weather it is a static web site. People who got into web dev after 2010 will say yes, people who watched HTML/JS evolve over it's lifetime will say no.

Re: Password protect a static HTML page

#262

Earlier quoted context omitted.

If your server supports it, a fast and easy way to password protect a page is to put it in a folder and password protect that folder with htaccess: https://ithemes.com/blog/what-is-the-htaccess-file/#password...

Keep in mind the same server will lock you out for a day or so if you autofill the wrong password, be warned. :D

HTTP basic authentication is stateless

Re: Password protect a static HTML page

#263
A 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.

Re: Password protect a static HTML page

#264

Earlier quoted context omitted.

Mostly because we have a bloody simple use case in this topic. HTML uses some Javascript to encrypt a file. Then later, the Javascript decrypts the file and returns it to normal. This is a "beginner level" cryptography situation. Yes, I know there's all sorts of traps all around the field of cryptography. But I also know that this particular use case is simple enough that beginners can try their hand at it, and proba…

> The fact that this subthread has gone down a rabbit-hole of hypotheticals that are _COMPLETELY IRRELEVANT_ I see what you’re saying, but the fact is that these hypotheticals are not irrelevant. They’re important intricacies and potential trip mines associated with implementing your own encryption.

There are a myriad of encryption libraries that have been implemented, reimplemented, and redesigned by various hackers.

In any case, I think reimplementing CBC is absolutely beginner level as far as implementation is concerned. Yes, you can be tripped up by various _uses_ of CBC, but the failure modes are extremely well studied at this point.

Of course, a proper AEAD implementation would avoid that. But AEAD is commonly established today with GCM, which is not beginner level. So now we're trapped. What am I supposed to tell a young programmer who is interested in playing around with encryption on their own?

Perhaps you wish to stop anyone from studying that subject. But on the contrary, I think the only way a programmer can truly learn this stuff is to implement the easiest stuff and try it out themselves from the ground up.

--------

The _proper_ advice, is... don't write your own production encryption. But... if you have to, stick with the simplest implementation that avoids the most common errors (side channels, timing attacks, etc. etc.), and focus on the simplest use cases that have the largest amount of history.

Of course, there's an entire class of crypto-bugs these days are found at the higher levels, in the "use of encryption" (ex: SSL3.0, TLS1.0, TLS1.1, etc. etc.). Nonce reuse, IV generation, in-advertent side channels due to padding oracles, etc. etc.

Even a "perfect" implementation of CBC will come across these crypto-bugs (and is why modern algorithms do focus on AEAD from the ground up these days, which largely avoids the problem).

So yes, there are a lot of traps and footguns in the world of encryption. But that's true of programming in general. Eventually, someone will want to make their own encryption, maybe the library doesn't work out just right (as is in this case: the Crypto-library doesn't have GCM mode implemented), and other modes need to be used. The use of CBC seems to be done properly here for static-HTML encryption.

Re: Password protect a static HTML page

#266
post #220

Earlier quoted context omitted.

I 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.

with 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) , in which you want to ensure that the decrypted data is _no…

In a real-life scenario, the server can access the key and collect it back (just farming location.hash)

Re: Password protect a static HTML page

#267

Earlier quoted context omitted.

Which 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/

Why 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.

That project and the parent do exactly what you wish:

- run encryption locally

- do not upload anything

You may not realize that’s the case because it’s a web form

Re: Password protect a static HTML page

#268

Earlier quoted context omitted.

You're incorrect CSS and JavaScript and images are also static, it doesn't have to be just HTML If you have a perl or bash or c backend generating html in response to http requests it's not static

You're assuming this is a backend. It is not. Do you consider generating an HTML file in a WYSIWYG editor like, say, "Dreamweaver" that outputs an .html no longer static because it was made by a program? That's absurd.

No, that's static, that's why I said "in response to an http request"

Re: Password protect a static HTML page

#269

Earlier quoted context omitted.

> The fact that this subthread has gone down a rabbit-hole of hypotheticals that are _COMPLETELY IRRELEVANT_ I see what you’re saying, but the fact is that these hypotheticals are not irrelevant. They’re important intricacies and potential trip mines associated with implementing your own encryption.

There are a myriad of encryption libraries that have been implemented, reimplemented, and redesigned by various hackers. In any case, I think reimplementing CBC is absolutely beginner level as far as implementation is concerned. Yes, you can be tripped up by various _uses_ of CBC, but the failure modes are extremely well studied at this point. Of course, a proper AEAD implementation would avoid that. But AEAD is comm…

> What am I supposed to tell a young programmer who is interested in playing around with encryption on their own?

Tell them to stop if they’re trying to do it for anything real, or do it as a toy protect that never sees the light of day. And if they select the latter, then they may as well try GCM.

Tell them to leave encryption writing to the professionals.

Re: Password protect a static HTML page

#270

Earlier quoted context omitted.

There are a myriad of encryption libraries that have been implemented, reimplemented, and redesigned by various hackers. In any case, I think reimplementing CBC is absolutely beginner level as far as implementation is concerned. Yes, you can be tripped up by various _uses_ of CBC, but the failure modes are extremely well studied at this point. Of course, a proper AEAD implementation would avoid that. But AEAD is comm…

> What am I supposed to tell a young programmer who is interested in playing around with encryption on their own? Tell them to stop if they’re trying to do it for anything real, or do it as a toy protect that never sees the light of day. And if they select the latter, then they may as well try GCM. Tell them to leave encryption writing to the professionals.

This entire subthread started because the github repo here used CBC mode (which was supported by the original writer's crypto library), rather than GCM mode (which was unsupported).

We're well deep into a "professional" discussion about the pros and cons of particular implementation details of cryptography.

------------

Go back to the top. Look at the Github code. See that it uses a crypto-library. What should have the original writer have done differently?

The answer is absolutely not "write their own implementation of GCM". They chose correctly: using a well known, well supported CBC mode of operation with AES. (And IMO, _IF_ CBC mode were unsupported, the correct move would have been to write CBC themselves, as it is far less complex than GCM, which includes GHASH and other such side-channel issues).

There's context to everything. From my understanding of this current situation, the CBC choice was perfectly valid.

Post reply on HN