Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@small-tech/auto-encrypt-localhost
Advanced tools
Automatically provisions and installs locally-trusted TLS certificates for Node.js https servers (including Express.js, etc.) using mkcert.
Automatically provisions and installs locally-trusted TLS certificates for Node.js® https servers (including Express.js, etc.) using mkcert.
Before creating your HTTPS server, uses mkcert to create a local certificate authority, adds it to the various trust stores, and uses it to create locally-trusted TLS certificates that are installed in your server.
You can reach your server via the local loopback addresses (localhost, 127.0.0.1) on the device itself and also from other devices on the local area network by using your device’s external IPv4 address.
npm i @small-tech/auto-encrypt-localhost
Import the module:
const AutoEncryptLocalhost = require('@small-tech/auto-encrypt-localhost')
Prefix your server creation code with a reference to the Auto Encrypt Localhost class:
// const server = https.createServer(…) becomes
const server = AutoEncryptLocalhost.https.createServer(…)
(You can find this example in the example/ folder in the source code. Run it by typing node example
.)
// Create an https server using locally-trusted certificates.
const AutoEncryptLocalhost = require('@small-tech/auto-encrypt-localhost')
const server = AutoEncryptLocalhost.https.createServer((request, response) => {
response.end('Hello, world!')
})
server.listen(() => {
console.log('Web server is running at https://localhost')
})
You can now reach your server via https://localhost, https://127.0.0.1, and via its external IPv4 address on your local area network. To find out what that is, you can run the following in the Node interpreter:
Object.entries(os.networkInterfaces())
.map(iface =>
iface[1].filter(addresses =>
addresses.family === 'IPv4')
.map(addresses => addresses.address)).flat()
You can access local servers via their IPv4 address over a local area network.
This is useful when you want to test your site with different devices without having to expose your server over the Internet using a service like ngrok. For example, if your machine’s IPv4 address on the local area network is 192.168.2.42, you can just enter that IP to access it from, say, your iPhone.
To access your local machine from a different device on your local area network, you must transfer the public key of your generated local root certificate authority to that device and install and trust it.
For example, if you’re on an iPhone, hit the /.ca
route in your browser:
http://192.168.2.42/.ca
The browser will download the local root certificate authority’s public key and prompt you to install profile on your iPhone. You then have to go to Settings → Profile Downloaded → Tap Install when the Install Profile pop-up appears showing you the mkcert certificate you downloaded. Then, go to Settings → General → About → Certificate Trust Settings → Turn on the switch next to the mkcert certificate you downloaded. You should now be able to hit https://192.168.2.42
and see your site from your iPhone.
You can also transfer your key manually. You can find the key at ~/.small-tech/auto-encrypt-localhost/rootCA.pem
after you’ve created at least one server. For more details on transferring your key to other devices, please refer to the relevant section in the mkcert documentation.
Note that on Linux, ports 80 and 443 require special privileges. Please see A note on Linux and the security farce that is “privileged ports”. If you just need a Node web server that handles all that and more for you (or to see how to implement privilege escalation seamlessly in your own servers, see Site.js).
You can specify a custom settings path for your local certificate authority and certificate data to be stored in by adding the Auto Encrypt Localhost-specific settingsPath
option to the options object you pass to the Node https
server. If not specified, the default settings path (~/.small-tech.org/auto-encrypt-localhost/) is used.
const AutoEncrypt = require('@small-tech/auto-encrypt-localhost')
const options = {
// Regular HTTPS server and TLS server options, if any, go here.
// Optional Auto Encrypt options:
settingsPath: '/custom/settings/path'
}
// Pass the options object to https.createServer()
const server = AutoEncryptLocalhost.https.createServer(options, listener)
// …
If you want to help improve Auto Encrypt Localhost or better understand how it is structured and operates, please see the developer documentation.
Small Technology Foundation is a tiny, independent not-for-profit.
We exist in part thanks to patronage by people like you. If you share our vision and want to support our work, please become a patron or donate to us today and help us continue to exist.
This is small technology.
If you’re evaluating this for a “startup” or an enterprise, let us save you some time: this is not the right tool for you. This tool is for individual developers to build personal web sites and apps for themselves and for others in a non-colonial manner that respects the human rights of the people who use them.
npm i -g @small-tech/auto-encrypt-localhost
auto-encrypt-localhost
Your certificates will be created in the ~/.small-tech.org/auto-encrypt-localhost directory.
Locally-trusted certificates do not work under Firefox. Please use Edge or Chrome on this platform. This is a mkcert limitation.
From lower-level to higher-level:
Adds automatic provisioning and renewal of Let’s Encrypt TLS certificates with OCSP Stapling to Node.js https servers (including Express.js, etc.)
A drop-in replacement for the standard Node.js HTTPS module with automatic development-time (localhost) certificates via Auto Encrypt Localhost and automatic production certificates via Auto Encrypt.
A complete small technology tool for developing, testing, and deploying a secure static or dynamic personal web site or app with zero configuration.
Linux has an outdated feature dating from the mainframe days that requires a process that wants to bind to ports < 1024 to have elevated privileges. While this was a security feature in the days of dumb terminals, today it is a security anti-feature. (macOS has dropped this requirement as of macOS Mojave.)
On modern Linux systems, you can disable privileged ports like this:
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0
Or, if you want to cling to ancient historic relics like a conservative to a racist statue, ensure your Node process has the right to bind to so-called “privileged” ports by issuing the following command before use:
sudo setcap cap_net_bind_service=+ep $(which node)
If you are wrapping your Node app into an executable binary using a module like Nexe, you will have to ensure that every build of your app has that capability set. For an example of how we do this in Site.js, see this listing.
Small Technology Foundation is a tiny, independent not-for-profit.
We exist in part thanks to patronage by people like you. If you share our vision and want to support our work, please become a patron or donate to us today and help us continue to exist.
Copyright © Aral Balkan, Small Technology Foundation.
Auto Encrypt Localhost is released under AGPL 3.0 or later.
FAQs
Automatically provisions and installs locally-trusted TLS certificates for Node.js https servers in 100% JavaScript.
The npm package @small-tech/auto-encrypt-localhost receives a total of 772 weekly downloads. As such, @small-tech/auto-encrypt-localhost popularity was classified as not popular.
We found that @small-tech/auto-encrypt-localhost 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.