![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
pagecrypt
Advanced tools
Changelog
6.0.0 - 2022-12-27
This is a major upgrade, reducing the amount of CSS by 50%, removing about 40% of the required third-party npm modules, and adding support for a custom number of password iterations
which allows for greatly improved security.
iterations
for both encryptHTML()
and encrypt()
. See usage examples in README to learn more.iterations
option through the CLI. See usage examples in README to learn more.globalThis
over window
in Node 19 - thanks @metonymReadme
Easily add client-side password-protection to your Single Page Applications and HTML files.
Inspired by MaxLaumeister/PageCrypt, but rewritten to use native Web Crypto API
and greatly improve UX + security. Thanks for sharing an excellent starting point to create this tool!
NOTE: Make sure you are using Node.js v16 or newer.
npm i -D pagecrypt
There are 4 different ways to use pagecrypt
:
pagecrypt/core
The encryptHTML()
and generatePassword()
functions are using Web Crypto API and will thus be able to run in any ESM compatible environment that supports Web Crypto API.
This allows you to use the same pagecrypt API in any environment where you can run modern JavaScript.
encryptHTML(inputHTML: string, password: string, iterations?: number): Promise<string>
import { encryptHTML } from 'pagecrypt/core'
const inputHTML = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
Secret
</body>
</html>
`
// Encrypt a HTML string and return an encrypted HTML string.
// Write it to a file or send as an HTTPS response.
const encryptedHTML = await encryptHTML(inputHTML, 'password')
// Optional: You can customize the number of password iterations if you want increased security.
const iterations = 3e6 // Same as 3_000_000
const customIterations = await encryptHTML(inputHTML, 'password', iterations)
generatePassword(length: number): string
import { generatePassword, encryptHTML } from 'pagecrypt/core'
// Generate a random password without any external dependencies
const password = generatePassword(64)
const encryptedHTML = await encryptHTML(inputHTML, password)
When working in a Node.js environment, you may prefer the pagecrypt
Node.js build. This also includes the encrypt()
function to read and write directly from and to the file system.
encrypt(inputFile: string, outputFile: string, password: string, iterations: number): Promise<void>
import { encrypt } from 'pagecrypt'
// Encrypt a HTML file and write to the filesystem
await encrypt('index.html', 'encrypted.html', 'password')
// You can optionally customize the number of password iterations
const iterations = 3e6 // Same as 3_000_000
await encrypt('index.html', 'encrypted.html', 'password', iterations)
NOTE: Importing pagecrypt
also gives you access to generatePassword()
and encryptHTML()
from pagecrypt/core
.
import { generatePassword, encryptHTML } from 'pagecrypt'
const password = generatePassword(48)
const iterations = 3e6 // Same as 3_000_000
const encrypted = await encryptHTML(inputHTML, password, iterations)
Encrypt a single HTML-file with one command:
npx pagecrypt <src> <dest> [password] [options]
Encrypt using a generated password with given length:
npx pagecrypt <src> <dest> -g <length>
TODO: Allow custom password iterations via the CLI too. TODO: Add tests for custom iterations in all three environments, CLI, browser and JS.
Description
Encrypt the <src> HTML file with [password] and save the result in the <dest> HTML file.
Usage
$ pagecrypt <src> <dest> [password] [options]
Options
-g, --generate-password Generate a random password with given length. Must be a number if used.
-v, --version Displays current version
-h, --help Displays this message
Examples
$ pagecrypt index.html encrypted.html password
$ pagecrypt index.html encrypted.html --generate-password 64
$ pagecrypt index.html encrypted.html -g 64
pagecrypt
in your build processUse either the pagecrypt
Node.js API or the CLI to automatically encrypt the builds for your single page applications.
npm i -D pagecrypt
package.json:
{
"devDependencies": {
"pagecrypt": "^5.0.0"
},
"scripts": {
"build": "...",
"postbuild": "pagecrypt index.html encrypted.html password"
}
}
pagecrypt
Since the output is a single HTML file, you can host it anywhere. This lets you bypass the need for server access to use HTTP basic authentication for password protection.
What this means in practice is that pagecrypt
enables you to deploy private apps and websites to any static frontend hosting platform, often for free. Great for prototypes and client projects.
To make it easier for your users to access protected pages, you can create a magic link by adding #
followed by your password to your deployment URL:
https://<link-to-your-page>#<password>
Then users can simply click the link to load the protected SPA or website - a really smooth UX! Just make sure to keep the link safe by sharing it via E2E-encrypted chats and emails.
#
, followed by your password
. E.g. https://example.com#password
https://
protocol to keep users safe.Since this magic link feature is using the URI Fragment, it will not be sent across the internet once the user clicks the link. Only the first part before the #
leaves the user's computer to fetch the HTML page, and the rest remains in the browser, used for local decryption. Additionally, the fragment is removed from the browser address field when the page loads. However, beware that the password remains as a history entry if you use magic links!
sessionStorage
saves the encryption key (which is derived from the password) until the browser is restarted. This is what allows the rapid page reloads during the same session - at the cost of decreasing the security on your local device.pagecrypt
only encrypts the contents of a single HTML file, so try to inline as much JS, CSS and other sensitive assets into this HTML file as possible. If you're unable to inline all sensitive assets, you can hide your other assets by placing them on another server, and then only reference the external resources within the pagecrypt
protected HTML file instead. Of course, these could in turn be protected or hidden if you need to. If executed correctly, this allows you to completely hide what your webpage or app is about by only deploying a single HTML file to the public web. Neat!Project structure:
/web
- Web frontend for public webpage (decrypt-template.html
). Built using Vite & Tailwind CSS./src/core.ts
- pagecrypt core library./src/index.ts
- pagecrypt Node.js library./src/cli.ts
- pagecrypt CLI./test
- simple testing setup./scripts
- local scripts for development tasks.npm install
in project root.First do one of the following:
npm test
to run the tests.npm run test:build
to first build a new version of pagecrypt
and then run the tests.Then run npm run verify
in another terminal and verify the test results at http://localhost:3000.
On the test results page you will find links to open output files in new tabs, buttons to copy passwords, and a special #
link to verify that magic links decrypt the page immediately when the page loads.
To test pagecrypt/core
and verify encryption in the browser, use the button at the bottom of the list. Download the file and then copy the password by clicking the button again to decrypt it. If you save the file to the same directory as the other generated files, you can use the links just like for other results. Use the reset button to encrypt another file.
Welcome to submit issues and pull requests!
FAQs
Easily add client-side password-protection to your Single Page Applications and HTML files.
The npm package pagecrypt receives a total of 855 weekly downloads. As such, pagecrypt popularity was classified as not popular.
We found that pagecrypt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.