Giter VIP home page Giter VIP logo

staticrypt's Introduction

password prompt preview
live example

StatiCrypt

Safely encrypt and password protect the content of your public static HTML file, to be decrypted in-browser without any back-end - to serve it over static hosting like Netlify, GitHub pages, etc. (see a live example).

StatiCrypt uses AES-256 and WebCrypto to encrypt your HTML file with your long password, and returns a static HTML page showing a password prompt that you can now safely upload anywhere, the page containing your encrypted content and decryption happening in javascript client side (see the details of how it works).

👉️ You can encrypt a file online in your browser (client side) at robinmoisson.github.io/staticrypt, or use the CLI to do it in your terminal or build process.

🌱 Supporting: I quit my software developer job after 10 years to teach mindfulness meditation in French. If you want to support StatiCrypt development you can do so by clicking on the sponsor button (or, well, come learn meditation!). See how donations are used. Thank you for your support!

Sponsor

CLI

Migration: v3 brings many improvements, a clearer CLI and simpler password_template over v2. See the migration guide from v2 to v3. v3 uses WebCrypto which is only available in HTTPS or localhost contexts, so if you need to use it in HTTP you'll need to use v2.

Installation

Staticrypt is available through npm as a CLI, install with

npm install staticrypt

You can then run it with npx staticrypt .... You can also install globally with npm install -g staticrypt and then just call staticrypt ... from anywhere.

Examples

These examples will create a .staticrypt.json file in the current directory (here's why). You can prevent this by setting the --config flag to false (a string).

Encrypt a file

Encrypt test.html and create a encrypted/test.html file (use -d my_directory to change the output directory):

# this will prompt you for the password, which won't stay in your terminal command history
staticrypt test.html

# you can also pass the password as an argument
staticrypt test.html -p <long-password>

Encrypt a file with the password in an environment variable

Set your long password in the STATICRYPT_PASSWORD environment variable (.env files are supported):

# the password is in the STATICRYPT_PASSWORD env variable, you won't be prompted
staticrypt test.html

Encrypt multiple HTML files at once

This will put the HTML files in an encrypted directory, created where you run the staticrypt command. Non-HTML files will be copied as-is from the input directory, so you can easily overwrite it with the encrypted directory if you want.

# this will encrypt test_A.html and test_B.html
staticrypt test_A.html test_B.html
# => encrypted files are in encrypted/test_A.html and encrypted/test_B.html

# you can also use the -r flag to recursively encrypt all files in a directory
staticrypt dir_to_encrypt -r
# => encrypted files are in encrypted/dir_to_encrypt/...

# if you don't want to include the directory name in the output path, you can use 
# `dir_to_encrypt/*` instead. `-r` will include potential subdirectories as well
staticrypt dir_to_encrypt/* -r
# => encrypted files are in encrypted/...

Replace all the files in a folder with encrypted ones

# 'dir_to_encrypt/*' as argument will select all the files in the directory ('-r' recursively), 
# and the '-d dir_to_encrypt' will put them in the same directory, overwriting the files
staticrypt dir_to_encrypt/* -r -d dir_to_encrypt

Get a shareable auto-decrypt link

The link contains the hashed password, that will auto-decrypt the file - you can include your file URL or leave blank. (⚠️ you should keep your .staticrypt.json so the salt is the same each time you encrypt, or re-encrypting will invalidate the link):

# you can also pass '--share' without specifying the URL to get the `#staticrypt_pwd=...` 
staticrypt test.html --share https://example.com/encrypted.html
# => https://example.com/encrypted.html#staticrypt_pwd=5bfbf1343c7257cd7be23ecd74bb37fa2c76d041042654f358b6255baeab898f

# add --share-remember to auto-enable "Remember-me" - useful if you want send one link to 
# autodecrypt multiple pages (you can also just append '&remember_me')
staticrypt test.html --share --share-remember
# => #staticrypt_pwd=5bfbf1343c7257cd7be23ecd74bb37fa2c76d041042654f358b6255baeab898f&remember_me

Pin the salt to use staticrypt in your CI or build step

If you want want the "Remember-me" or share features to work accross multiple pages or multiple successive deployment, the salt needs to stay the same (see why). If you run StatiCrypt in a CI step, you can pin the salt in two ways:

  • either commit the .staticrypt.json config file - you can generate a random salt and config file on your local machine with:

    staticrypt --salt
  • or hardcode the salt in the encryption command in the CI script:

    staticrypt test.html --salt 12345678901234567890123456789012

See an example of how to use StatiCrypt in a CI build step in this community project: a-nau/password-protected-website-template

Customize the password prompt

Customize the HTML to have the encrypted page match your style (see the FAQ for a full custom template):

# use your own custom template
staticrypt test.html -t my/own/password_template.html

# or customize the default template
staticrypt test.html \
    --template-color-primary "#fd45a4" \
    --template-title "My custom title" \
    --template-instructions "To unlock this file, you should..." \
    # ...

Decrypt files from the CLI

Decrypt files you encrypted earlier with StatiCrypt straight from the CLI by including the --decrypt flag. (So if you want, you can keep only the encrypted files.) The -r|--recursive flag and output -d|--directory option work the same way as when encrypting (default name for the output directory is decrypted):

staticrypt encrypted/test.html --decrypt
# => decrypted file is in decrypted/test.html

CLI Reference

The password argument is optional if STATICRYPT_PASSWORD is set in the environment or .env file.

Usage: staticrypt <filename> [<filename> ...] [options]

Options:
      --help                      Show help                            [boolean]
      --version                   Show version number                  [boolean]
  -c, --config                    Path to the config file. Set to "false" to
                                  disable.[string] [default: ".staticrypt.json"]
  -d, --directory                 Name of the directory where the generated
                                  files will be saved. If the '--decrypt' flag
                                  is set, default will be 'decrypted'.
                                                 [string] [default: "encrypted"]
      --decrypt                   Include this flag to decrypt files instead of
                                  encrypt.            [boolean] [default: false]
  -p, --password                  The password to encrypt your file with. Leave
                                  empty to be prompted for it. If
                                  STATICRYPT_PASSWORD is set in the env, we'll
                                  use that instead.     [string] [default: null]
  -r, --recursive                 Whether to recursively encrypt the input
                                  directory.          [boolean] [default: false]
      --remember                  Integer: expiration in days of the "Remember 
                                  me" checkbox that will save the (salted + 
                                  hashed) password in localStorage when entered 
                                  by the user. Set to "false" to hide the box. 
                                  Default: "0", no expiration.      [default: 0]
  -s, --salt                      Generate a config file or set the salt
                                  manually. Pass a 32-character-long hexadecimal
                                  string to use as salt, or leave empty to
                                  generate, display and save to config a random
                                  salt. This won't overwrite an existing config
                                  file.                                 [string]
      --share                     Get a link containing your hashed password
                                  that will auto-decrypt the page. Pass your URL
                                  as a value to append
                                  "#staticrypt_pwd=<hashed_pwd>", or leave empty
                                  to display the hash to append.        [string]
      --share-remember            Whether the share link should auto-enable
                                  'Remember-me'.      [boolean] [default: false]
      --short                     Hide the "short password" warning.
                                                      [boolean] [default: false]
  -t, --template                  Path to custom HTML template with password
                                  prompt.
               [string] [default: "/code/staticrypt/lib/password_template.html"]
      --template-button           Label to use for the decrypt button. Default:
                                  "DECRYPT".       [string] [default: "DECRYPT"]
      --template-color-primary    Primary color (button...)
                                                   [string] [default: "#4CAF50"]
      --template-color-secondary  Secondary color (page background...)
                                                   [string] [default: "#76B852"]
      --template-instructions     Special instructions to display to the user.
                                                          [string] [default: ""]
      --template-error            Error message to display on entering wrong
                                  password.  [string] [default: "Bad password!"]
      --template-placeholder      Placeholder to use for the password input.
                                                  [string] [default: "Password"]
      --template-remember         Label to use for the "Remember me" checkbox.
                                               [string] [default: "Remember me"]
      --template-title            Title for the output HTML page.
                                            [string] [default: "Protected Page"]
      --template-toggle-hide      Alt text for toggling password visibility -
                                  "hide" action.
                                             [string] [default: "Hide password"]
      --template-toggle-show      Alt text for toggling password visibility -
                                  "show" action.
                                             [string] [default: "Show password"]

HOW STATICRYPT WORKS

So, how can you password protect html without a back-end?

StatiCrypt uses WebCrypto to generate a static, password protected page that can be decrypted in-browser. You can then just send or upload the generated page to a place serving static content (github pages, for example) and you're done: the page will prompt users for a password, and the javascript will decrypt and load your HTML, all done in the browser.

So it basically encrypts your page and puts everything in a user-friendly way to enter the password in the new file.

FAQ

Is it secure?

Simple answer: your file content has been encrypted with AES-256, a popular and strong encryption algorithm. You can now upload it to any public place and no one will be able to read it without the password. So if you used a long, strong password, then yes it should be secure.

Longer answer: actual security depends on a number of factors and on the threat model you want to protect against. Because your full encrypted file is accessible client side, brute-force/dictionary attacks would be easy to do at a fast pace: use a long, unusual password. We recommend 16+ alphanum characters, Bitwarden is a great open-source password manager if you don't have one already.

On the technical aspects: we use AES in CBC mode (see a discussion on why this mode is appropriate for StatiCrypt in #19) and key stretching with 600k PBKDF2-SHA256 iterations to slow down brute-force attacks (which is the recommended number by OWASP - read a detailed report on why this number and the security model of StatiCrypt in #159).

Transparency disclaimer: I am not a cryptographer. I try my best to get the implementation right, listen to feedback and be transparent in stewarding StatiCrypt. But please adjust accordingly depending on your threat model: if you are an at-risk activist or have very sensitive crypto assets to protect, you might want to use something else.

Can I customize the password prompt?

Yes! Just copy lib/password_template.html, modify it to suit your style and point to your template file with the -t path/to/my/file.html flag.

Be careful to not break the encrypting javascript part, the variables replaced by StatiCrypt are in this format: /*[|variable|]*/0. Don't leave out the 0 at the end, this weird syntax is to avoid conflict with other templating engines while still being read as valid JS to parsers so we can use auto-formatting on the template files.

Can I support multiple users with different passwords?

At the moment you can only use one passsword per page (though there is a reflection on supporting decryption with multiple different passwords in #158). If you want to support multiple users so you can invalidate passwords individualy, the current recommended way is the following:

  • Make a script that will encrypt your files with different passwords and different output folders

    staticrypt test.html -p <john-password> -d john
    ...
    
  • send each user the link to their folder with their password: https://example.com/john/test.html

In a way, the username input becomes the folder in the https://example.com/<username> URL, and the password input is the HTML form. You can then invalidate a single password by changing it in your script and running it again.

Why doesn't StatiCrypt work in HTTP?

From version 3.x StatiCrypt only uses the browser WebCrypto API, which makes it more secure but is only available in HTTPS or on localhost. If you need to use it in HTTP, you can use version 2.x which offers the CryptoJS engine as an option, and will work everywhere.

Why does StatiCrypt create a config file?

The "Remember me" feature stores the user password hashed and salted in the browser's localStorage, so it needs the salt to be the same each time you encrypt otherwise the user would be logged out when you encrypt the page again. The config file is a way to store the salt in between runs, so you don't have to remember it and pass it manually.

When deciding what salt to use, StatiCrypt will first look for a --salt flag, then try to get the salt from the config file, and if it still doesn't find a salt it will generate a random one. It then saves the salt in the config file.

If you don't want StatiCrypt to create or use the config file, you can set --config false to disable it.

The salt isn't secret (it's publicly visible on the encrypted file), so you don't need to worry about hiding the config file. If you're encrypting as part of a CI step, you can commit the .staticrypt.json file so it's accessible to your build server.

How does the "Remember me" checkbox work?

The CLI will add a "Remember me" checkbox on the password prompt by default (--remember false to disable). If the user checks it, the (salted + hashed) password will be stored in their browser's localStorage and the page will attempt to auto-decrypt when they come back.

If no value is provided the stored password doesn't expire, you can also give it a value in days for how long should the store value be kept with --remember NUMBER_OF_DAYS. If the user reconnects to the page after the expiration date the stored value will be cleared.

"Logging out"

You can clear StatiCrypt values in localStorage (effectively "logging out") at any time by appending staticrypt_logout to the URL fragment (https://mysite.com#staticrypt_logout).

Encrypting multiple pages

This allows encrypting multiple page on a single domain with the same password: if you check "Remember me", you'll have to enter your password once then all the pages on that domain will automatically decrypt their content. Because the hashed value is stored in the browser's localStorage, this will only work if all the pages are on the same domain name.

Is the "Remember me" checkbox secure?

In case the value stored in the browser becomes compromised an attacker can decrypt the page, but because it's stored salted and hashed this should still protect against password reuse attacks if you've used the password on other websites (of course, please use a long, unique password nonetheless).

Can I remove the "Remember me" checkbox?

If you don't want the checkbox to be included, you can set the --remember false flag to disable it.

Contributing

🙏 Thank you!

Opening PRs and issues

I administer the project when I have time and motivation. You're free to open PRs if you're ok with having no response for a (possibly very) long time and me possibly ending up getting inspiration from your proposal but merging something different myself (I'll try to credit you though). Apologies in advance for the delay, and thank you for making the project better!

Opening issues with suggestions and bug reports is welcome.

If you find a serious security bug please open an issue or contact me following the instructions in SECURITY.md and I'll try to fix it relatively quickly.

Security

You can find the security policy and secure contact details in SECURITY.md. If you have general ideas or feedback around the implementation or StatiCrypt security model they are very welcome, if it's not extra sensitive feel free to open an issue. A couple of place where security was discussed previously are #19 and #159.

Guidelines to contributing

Source map

  • cli/ - The command-line interface published to NPM.
  • example/ - Example encrypted files, used as an example in the public website and for manual testing.
  • lib/ - Files shared across www and cli.
  • scripts/ - Convenient scripts for building the project.
  • index.html - The root of the in-browser encryption site hosted at https://robinmoisson.github.io/staticrypt. Kept in the root of the repo for easy deploys to GitHub Pages.

Build

When editing StatiCrypt logic, we want to sync the changes to the browser version, the CLI and the example files, so all of them use the new logic. To do so, run:

npm install
npm run build

Test

The testing is done manually for now - you can run build, then open example/encrypted/example.html and check everything works correctly. There is an open issue to automate this in #136, feel free to contribute to setting up a test framework if you'd like!

Community and alternatives

Here are some other projects and community resources you might find interesting (this is included as an informative section, I haven't personally vetted any of those).

If you have a StatiCrypt project you'd like to share, feel free to open an issue describing it.

Based on StatiCrypt, tutorials and projects

Template to host an encrypted single page website with Github Pages: a-nau/password-protected-website-template is a demonstration of how to build a protected page on Github Pages, integrating with Github Actions.

Alternatives to StatiCrypt

MaxLaumeister/PageCrypt is a project with similar features in a different style (I think it was created before StatiCrypt).

staticrypt's People

Contributors

aaroncoplan avatar bfred-it avatar bobwhitelock avatar dth292 avatar ferhatelmas avatar fregante avatar hurrymaplelad avatar j2team avatar literallyvoid avatar oleteacher avatar pierreneter avatar potomak avatar robinmoisson avatar royfrancis avatar sebtoun avatar xdsoar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

staticrypt's Issues

[Request] Forget checkbox

It will be useful to add a visual representation of the mysite.com?staticrypt_logout option when Default: "0", no expiration was selected (the default case).

When checked, the clearLocalStorage() function will be executed on form submission.

Please, ignore this, my custom template always shows logon part, even when there is remembered password.

Encrypt CLI

Would it be possible to make a CLI version of staticrypt that could be scripted into for automatic deployment?

I have several scripts that pull data and build html report pages. I'm imagining generating those pages as I do now, then running them through the staticrypt CLI to generate encrypted html pages I can then upload to my hosting service.

Bug key.clamp not a function

The error is:

/home/adminy/project_test/node_modules/crypto-js/hmac.js:58
                    key.clamp();
                        ^

TypeError: key.clamp is not a function
    at Object.init (/home/adminy/project_test/node_modules/crypto-js/hmac.js:58:18)
    at subtype.init (/home/adminy/project_test/node_modules/crypto-js/core.js:86:46)
    at Object.create (/home/adminy/project_test/node_modules/crypto-js/core.js:113:32)
    at Object.compute (/home/adminy/project_test/node_modules/crypto-js/pbkdf2.js:75:30)
    at C.PBKDF2 (/home/adminy/project_test/node_modules/crypto-js/pbkdf2.js:138:36)
    at Object.hashPassphrase (/home/adminy/project_test/node_modules/staticrypt/lib/cryptoEngine/cryptojsEngine.js:50:35)
    at encode (/home/adminy/project_test/node_modules/staticrypt/lib/codec.js:19:43)
    at Object.<anonymous> (/home/adminy/project_test/node_modules/staticrypt/cli/index.js:170:26)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)

I literally just installed the library and then tried to run it on a blank compiled solidjs project:

npx degit solidjs/templates/js project_test
cd project_test
npm i https://github.com/robinmoisson/staticrypt
npm run build
npx staticrypt dist/index.html

Running this on node version v18.9.0 and on a macos Ventura 13.0.1.

I need this altered code with out passphrase

In one of my site I need to hide the real code from visitors, I think this can be done with this script. But I dont need passphrase for this. I need to hide the links of my videos. How to achieve this? In this script the real source code is hiding, right?

Flash of Unstyled Content

I'm using this to encrypt a Hugo made static site.

I get a consistent FOUC when navigating through the site pages.

Are there any proposed solutions to this?

CSS Styles being stripped out

Really enjoying Staticrypt!

I have experienced an issue when styles like this in page:

a:link {color: #339999; text-decoration: none}

The "{color: #339999; text-decoration: none}" is totally stripped from page which results in layout issues.

When possible, we call the css file from server but in our case final page used on school network and need all css in the final page.

Have looked at:

var renderTemplate = function (tpl, data) {
        return tpl.replace(/{(.*?)}/g, function (_, key) {
            return data && data[key] || '';
        });

Is it possible to use double {{}} brackets? attempted to change like this but no work:

var renderTemplate = function (tpl, data) {
        return tpl.replace(/{{(.*?)}}/g, function (_, key) {
            return data && data[key] || '';
        });

Any input greatly appreciated.

Adding CKEditor to Instructions

Very nice project!

Wanting to use in classroom but users will be 10-12 years old and need to use editor for instructions area.

I have successfully added but submit button is not saving the content from CKEditor. Have failed in many attempts to get working and in hopes you could provide some insight?

This is added in head tags:
<script src="https://cdn.ckeditor.com/4.7.0/standard/ckeditor.js"></script>

The textarea looks like this:
<textarea name="editor1" class="form-control" id="instructions" placeholder="Default: nothing."></textarea>

With this in footer:

<script>
CKEDITOR.replace( 'editor1' );
</script>

Any input greatly appreciated.

Susan

[Request] Encrypt with passphrase stored as an environment variable

Hello! I’m loving this package and I’m using it in several private repos; though, it would be great if I could implement it in public projects without giving away the security through package.json.

Would it be possible to encrypt using passphrases stored in the .env file or Netlify’s environment variables?

Ability to decrypt with multiple passphrases

Can this feature be implemented?
Adding multiple passphrases to decrypt successfully.
I'm still wondering if I can open a unique link instead of html when page is successfully decrypted?
If yes, how?

Embed external sources

This is a neat project, but it would be nice to be able to not depend on external sources; maybe add a checkbox that says "embed external sources"?

Help Wanted

I recently checked that staticrypt is using cryptojs whcih in not being maintained since 2016 when it was last updated

  • so please can you replace cryptojs with some other javascript module which is using latest techniques for protection
    Thnks

Can't decrypt recently crypted links

Hi,

I use https://robinmoisson.github.io/staticrypt/ to crypt some links for my one-page html app.

I'm changing these links every year.

The problem is that I can decrypt the links created last year, but when creating a new link with the same password the decrypt function doesn't decrypt it.

	encryptedHMAC = encryptedMsg.substring(0, 64);
	encryptedHTML = encryptedMsg.substring(64);
	decryptedHMAC = CryptoJS.HmacSHA256(encryptedHTML, CryptoJS.SHA256(passphrase).toString()).toString();

For old links encryptedHMAC/decryptedHMAC are equal, but for the newly created links they differ.

function decrypt (encryptedMsg, pass) {
		var keySize = 256;
		var iterations = 1000;
		var salt = CryptoJS.enc.Hex.parse(encryptedMsg.substr(0, 32));
		var iv = CryptoJS.enc.Hex.parse(encryptedMsg.substr(32, 32))
		var encrypted = encryptedMsg.substring(64);
		var key = CryptoJS.PBKDF2(pass, salt, {
				keySize: keySize/32,
				iterations: iterations
		});
		var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
				iv: iv,
				padding: CryptoJS.pad.Pkcs7,
				mode: CryptoJS.mode.CBC
		}).toString(CryptoJS.enc.Utf8);
		return decrypted;
}

Are there any recent changes on staticrypt resulting in this issue? Please contact me at [email protected] if you need a detailed example and old and new encrypted strings for a test.

Happy New Year!
Sergey

[Request] Custom error message

It would be neat if you pass a custom error message right from the CLI arguments.

Something like --error-message 'Try again!' that could be referenced in the HTML template as {error_message}.

CryptoJS.SHA256 without toString()

I was trying to make a CLI shell script that does the generation side of staticrypt, and I can't seem to manage to reproduce the same HMAC with openssl dgst.

It seems that this line:
https://github.com/robinmoisson/staticrypt/blob/gh-pages/index.html#L200

var hmac = CryptoJS.HmacSHA256(encrypted.toString(), CryptoJS.SHA256(passphrase)).toString();

is doing something maybe weird, or that I don't understand (?)

These two calls are doing something different:

var hmac1 = CryptoJS.HmacSHA256("hello", CryptoJS.SHA256("key")).toString();
var hmac2 = CryptoJS.HmacSHA256("hello", CryptoJS.SHA256("key").toString()).toString();

gives:

hmac1: f1083d8619b5a4067c55eb2b718eca4a5340d7b297be894063893e596285d74e
hmac2: 613a0711a03eabab03c7a66d6e3d4debeef0926fcdab7666e1611a894ef40ed9

curly braces in CLI result in Syntax Error

My Yarn project encrypts an HTML after building with Eleventy and SASS with this command:

"build:encrypt": "find ./_site/wip -type f -name '*.html' -exec staticrypt {} morpho -o {} -f ./password.html \\;"

Though, it mysteriously started printing this message when I moved from npm to Yarn:

Syntax Error: Expected "$", "$'", "$(", "$((", "${", "&", "&&", "'", ";", "<", "<&", "<<<", ">", ">&", ">>", "\"", "\"\"", "\\", "|", "|&", "||", [ \t], [0-9], or end of input but "{" found (line 1, column 58).

Column 58 in this command corresponds to the first opening curly brace {.

It used to work fine a couple months prior and I can’t find much info on this error.

[Request] Automated tests?

Building on #135, automating the example_encrypted.html flow would help me contribute faster.

Starting with an issue rather than I PR 'cause I noticed and appreciate that this package currently has very few dependencies. We'd need to add a dev dependency on something like puppeteer to set this up.

Concerns? Safe to assume we'd prefer Node's baked-in test harness vs something like Jest?

Download doesn't work in MSIE 11

When I click the download button in MSIE 11, I get a new tab with a bunch of content in the address bar. But, no file download happens.

This is the content that lands in the address bar (sic)

data:attachment/text,%3C!doctype%20html%3E%0A%3Chtml%20class%3D%22staticrypt-html%22%3E%0A%3Chead%3E%0A%20%20%20%20%3Cmeta%20charset%3D%22utf-8%22%3E%0A%20%20%20%20%3Ctitle%3EProtected%20Page%3C%2Ftitle%3E%0A%20%20%20%20%3Cmeta%20name%3D%22viewport%22%20content%3D%22width%3Ddevice-width%2C%20initial-scale%3D1%22%3E%0A%0A%20%20%20%20%3C!--%20do%20not%20cache%20this%20page%20--%3E%0A%20%20%20%20%3Cmeta%20http-equiv%3D%22cache-control%22%20content%3D%22max-age%3D0%22%2F%3E%0A%20%20%20%20%3Cmeta%20http-equiv%3D%22cache-control%22%20content%3D%22no-cache%22%2F%3E%0A%20%20%20%20%3Cmeta%20http-equiv%3D%22expires%22%20content%3D%220%22%2F%3E%0A%20%20%20%20%3Cmeta%20http-equiv%3D%22expires%22%20content%3D%22Tue%2C%2001%20Jan%201980%201%3A00%3A00%20GMT%22%2F%3E%0A%20%20%20%20%3Cmeta%20http-equiv%3D%22pragma%22%20content%3D%22no-cache%22%2F%3E%0A%0A%20%20%20%20%3Cstyle%3E%0A%20%20%20%20%20%20%20%20.staticrypt-hr%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin-top%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin-bottom%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border%3A%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-top%3A%201px%20solid%20%23eee%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20.staticrypt-page%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20360px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%208%25%200%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A%20auto%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20box-sizing%3A%20border-box%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20.staticrypt-form%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3A%20relative%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20z-index%3A%201%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20%23FFFFFF%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20max-width%3A%20360px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A%200%20auto%20100px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%2045px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20box-sha

If I may be of assistance by testing something and reporting the results, please let me know.

Embed option is broken

When using the embed option (-e flag) the cli outputs Failure: embed file does not exist! because crypto-js file is looked for inside working directory instead of __dirname.

Where do I place the hidden content?

So I am trying to create this content that can be accessed after entering the password. Currently whatever I place shows up with the passport prompt screen.

Gatsby site inconsistently asking for password

I've got this running on a Gatsby site hosted on Netlify as well as Vercel to rule out anything weird on the Netlify end. The problem I have is that I can inconsistently access protected pages without a password. Sometimes it asks me for a password, other times it does not. A hard refresh almost always triggers the password prompt on the URL.

Everything is configured in my package.json file located at https://github.com/waylonrobert/my-gatsby-site/blob/main/package.json.

Essentially Netlify and Vercel runs these two commands at deploy, in order:

npm run build, which is an alias for the gatsby build command that generates the static pages (in this case the secret page located in public/protected).

npm run _encrypt, which runs this command
"find ./public/protected -type f -name '*.html' -exec staticrypt {} password -o {} \\;" (and yes I know storing this in a public repo is bad practice, as is using password as the password, but this is just for troubleshooting right now)

Any thoughts on why this is inconsistency is happening? @robinmoisson

Encrypting Multiple Pages

How does one encrypt multiple pages in a website?

I mean, entering the password on one page decrypts all other pages at once.

And all routes are protected as well.

Download button doesn't work in MS Edge 38

When I click the Download button in Edge, I get a new blank tab with no content in the address bar. That's it.

Let me know if I can help by following troubleshooting instructions you provide!

Replace crypto-js by browser native WebCrypto ?

Pro/Cons that I see:

Pros

  • no dependencies at all
  • smaller output (not a big issue I think, minified crypto-js is quite lean already)
  • no need to update the lib, always as up to date as the browser

Cons

  • at encryption time: I see it as going from using the crypto implementation of a single library that can be audited to leaving it to each user's browser, so the responsability of checking that their browser is up to date/bugfree on that point falls on each user.

    Makes sense ? Is there any data on the crypto implementation of that API in browsers ?

  • it might be nice to have a cli tool that can be inserted into one's workflow to update the encrypted files automatically. We can't use the browser API for that, crypto-js as a node library could also be used. Though the website and cli could use different tools.

  • probably wider support (for now) for crypto-js but that'd need to be checked and by how much :)

Keeping in mind that it would be possible to use different solutions for encrypting/decrypting: encrypting needs to be the safest option, decrypting the most convenient one.

Out of memory exception

Hi,

I tried cryptojs with a bit larger files (~140 Meg) and it results in uncaught exception: out of memory. I even modified the code to open the file, read the content and pass it to the encryptor.

Any chance on fixing this?

Thanks.
Behdad.

generation or download in Firefox 55.0a1

I don't get any messages in the javascript console when I click 'generate' nor 'download'. But, the downloaded document is truncated, less than 700 bytes.

If you give me instructions, I'll perform them to test this issue.

No default body tag.

Found a nice edge case for ya 🗡

Opening:

<link href="https://fonts.googleapis.com/css?family=Lilita+One" rel="stylesheet">

<style>
  html {
    background-color: #f1f1f1;
    font-family: 'Lilita One', cursive;
    animation-duration: 5000ms;
    animation-fill-mode: both;
    animation-iteration-count: infinite;
    backface-visibility: visible;
    animation-name: colors;
    animation-timing-function: linear;
  }

  @keyframes colors {
    0% {
      transform: rotate3d(0deg);
      background-color: #f10a75;
      color: #fed024;
    }
    50% {
      background-color: #fed024;
      color: #f10a75;
    }
    100% {
      transform: rotateY(360deg);
      background-color: #f10a75;
      color: #fed024;
    }
  }

  body {
    margin: 0;
    text-align: center;
    line-height: 100vh;
  }

  body:after {
    content: "Coming Soon";
    font-size: 5vh;
  }
</style>

will display a spinning loading message, while after it has been ran through staticrypt it will not due to no default body tag being generated.

Can't run from file URL

When I open the URL file:///path/to/repo/index.html in my Chrome or Firefox browser, and fill out the form, the Download-HTML-File button does not get enabled, even after adding a config to disable-cross-domain-policy.

How to work with this from a file URL?

Page keeps 'loading' after decrypt

I'm using Firefox 56.0a1.

After I decrypt a page (short text string, not HTML), the spinner on the tab keeps going until I hit the escape key.

Allow caching of password

I have a Hugo website, using Netlify, and would like to know how to not require all pages on the site to ask for the password if it has already been entered on another page. Any help would be greatly appreciated. The following is my Netlify build command
hugo && npm install && find public -type f -name '*.html' -exec staticrypt {} ****** \\;
Thanks,
Eli

Github Action workflow does not work

Hi,
Not sure if staticrypt works in Github Actions.
I like to use staticrypt to encrypt my Jekyll _site dir (or html files)

by default it does not create the .staticrypt.json file (pushed a blank one)
but when running the below command it shares an error

sudo npx staticrypt /home/runner/work/example.github.io/example.github.io/_site/index.html password123

Idea is to let github actions build the Jekyll _site first, then install the npm module and run the encryption, but no luck.
and tips on how to run this in Github Pages?


Run sudo npx staticrypt /home/runner/work/example.github.io/example.github.io/_site/index.html password123
sudo npx staticrypt /home/runner/work/example.github.io/example.github.io/_site/index.html password123

shell: /usr/bin/bash -e {0}
undefined:2
SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at Object. (/usr/local/lib/node_modules/staticrypt/index.js:177:19)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:[7]
at node:internal/main/run_main_module:17:47
Error: Process completed with exit code 1.

"Remember me" not working - reusing same salt across multiple pages

Hi,

I tried to use the "Remember me" checkbox in order to decrypt pages with the same password, without needing to retype it several times.

But it doesn't seem to work as expected:

  • When entering the password on the first page, this page is decrypted. All good.
  • When I try to access a second page, I get a password prompt again instead of the decrypted page.

From what I experienced, the password seems to be remembered only for the single page on which I click the checkbox.

For testing and trying to set up the feature on my site, I tried first with 2 very basic html files, encrypted with the classic command:
staticrypt a.html test
staticrypt b.html test
Then I tried to access a_encrypted.html and b_encrypted.html by typing the password "test" only once.
My website is made with Hugo, I tried both on my localhost server and deployed on my github pages hosting without success.

Am I doing something wrong?

Thanks,
Sébastien.

npx staticrypt fails

My standard build script:

bundle exec jekyll build && npx staticrypt _site/thisfile.html myuniquepassword --salt 9872346ef723ab374 -o _site/thisfile.html -f "_includes/extensions/password_template.html"

fails with error message

fs.readFileSync(...).replaceAll is not a function

This is the first time it has failed after the best part of a year of regular use. Has something changed?

Extension for encrypting an entire website

Staticrypt is great! I extended it a bit so that it could be used to encrypt an entire website. Here are my steps:

  1. Change the template so that it stores the password in localStorage once entered.
  2. Run staticrypt on all html files.
  3. Now we have a website where the user can log in once and then navigate to other pages without entering in their password for each page. (demo at https://epicfaace.github.io/ghpages-private-test/, password is "password")

@robinmoisson would you be willing to accept PRs to modify staticrypt so that it can work with these kinds of workflows more easily? Essentially, staticrypt could then work out-of-the-box to let people easily deploy a password-protected github pages website (or, really, any static website).

I'm thinking of updating the staticrypt CLI options with the following parameters:

Usage: staticrypt <filename or directory> <passphrase> [options]

Options:
  --help               Show help                                       [boolean]
  --version            Show version number                             [boolean]
  -e, --embed          Whether or not to embed crypto-js in the page (or use an
                       external CDN)                   [boolean] [default: true]
  -o, --output         File name / path for generated encrypted file
                                                        [string] [default: null]
  -t, --title          Title for output HTML page
                                            [string] [default: "Protected Page"]
  -i, --instructions   Special instructions to display to the user.
                                                        [string] [default: null]
  -f, --file-template  Path to custom HTML template with password prompt.
                          [string] [default: "[...]/cli/password_template.html"]
  -i, --in-place   Whether to modify input file(s) in place.
  -p, --persist-type   Whether to persist the password in the user's browser.
                            Can be set to "localStorage", "sessionStorage", or "cookie".
                            [string] [default: null]

Then, generating a static site and deploying it to GitHub Pages might be as easy as doing the following:

npm run build # generates files in `dist`
staticrypt dist -i -p localStorage
gh-pages -d dist

Some potential improvements:

  1. It would be good to have an option such as --logout-url that allows a logout page to be generated; the user can then link to this logout page on the static site which should clear the password from the user's localStorage / cookies.
  2. It seems okay, but not ideal, to store the plain password in the user's localStorage / cookies. Could we make the stored password automatically expire (if there's some cryptographic way to make a token valid only for a particular amount of time, that would be great -- otherwise, we could just maybe delete a cookie after a certain period of time)?
  3. Allowing provisioning of multiple users and passwords.

Related to #110, #114.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.