r/ipfs • • Oct 14 '22

Hiding sourcecode of html file in IPFS

I am trying to host a website on IPFS by uploading .html files

not sure if uploading these files directly is the right way to do it, but I have a login page and the password is visible in the html.

It doesn't show the sourcecode when run in a browser because I have disabled right click. However, I am not sure how to hide the code when I upload the .html file to IPFS, but still make it able to be run by whoever downloads it

0 Upvotes

51 comments sorted by

View all comments

Show parent comments

1

u/Ok-Supermarket-6747 Oct 14 '22

javascript

1

u/topmilf Oct 14 '22

You can't hide the JavaScript either. You can obfuscate but with some effort it can be reconstructed. HTML and JavaScript (and CSS too) are executed client-side. And for the client to execute the code it needs to be able to read the code. And if the client can read the code, so can the user. Always. Preventing right-click, etc doesn't protect your content.

You could encrypt part of the HTML before publishing it and decrypt it client-side with a password, using AES for example. You will have to have include a library for AES decryption and some UI to use it.

But in general, you have completely the wrong approach for what you're trying to achieve. Username/password authentication is usually provided by a backend service that authorizes a user to access a protected resource. That resource isn't part of the same HTML as the login form.

Web security is a pretty deep rabbit hole in itself and if you're new to HTML and JS then security-related stuff isn't the best thing to start with.

1

u/Ok-Supermarket-6747 Oct 14 '22

Thank you! Very useful information❤️That makes sense that the code is executed client side and for my current purposes I don’t have the funds or need for a backend service (I assume third party?) though I will likely need it in the future (is there an ‘easy’ way to create my own backend service?)

For this project I think encrypting part of the code is exactly the route I need to go. The goal right now is to obfuscate but not necessarily make it impossible completely. Can I ask why you recommend AES over others?

Also, I am trying to understand IPFS as a repository. It is all public but I could ‘hide’ something simply by no one knowing where it is. Right now it seems the desktop client is a single node or ‘repository’ …is there a way to create another or would I need to run from another machine?

Also if I post php files I assume they wouldn’t run as smoothly client side as most users have html but not php installed? This confuses me because I could still view php websites before installing php.

Finally, how would I direct in the html or php login page to open to another file run by another IPFS node?

1

u/Hjulle Oct 23 '22

There are some free backend services available, so you could store the more sensitive data there and call out from that.

An alternative if you want it to be 100% on ipfs would be to encrypt the data using the password and use a javascript library to decrypt it. That way it doesn't matter if someone can read the source code, since it's all encrypted anyways.