
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
koa-force-https
Advanced tools
Koa.js middleware to force HTTPS connection on any incoming requests
Koa.js middleware to force HTTPS connection on any incoming requests. In case of a non-encrypted HTTP request, koa-force-https
automatically redirects to an HTTPS address.
npm install koa-force-https --save
Name | Type | Default | Description |
---|---|---|---|
port | Integer | HTTPS port (port :443 is automatically removed from the URL) | |
hostname | String | same host | Hostname for redirect |
httpStatusCode | Integer | 301 | HTTP status code for redirect |
const Koa = require('koa');
const forceHTTPS = require('koa-force-https');
const app = new Koa();
app.use(forceHTTPS());
http
to https
const fs = require('fs');
const http = require('http');
const https = require('https');
const Koa = require('koa');
const forceHTTPS = require('koa-force-https');
const options = {
key: fs.readFileSync('ssl-certificate.key'),
cert: fs.readFileSync('ssl-certificate.crt')
}
const app = new Koa();
app.use(forceHTTPS());
app.use((ctx) => {
ctx.body = 'Hello! This is an HTTPS connection.';
});
// Runs 2 servers for the application
// Requests from the HTTP server will be redirected to the HTTPS server
http.createServer(app.callback()).listen(80);
https.createServer(options, app.callback()).listen(443);
Request URL | Status Code | Location |
---|---|---|
http://example.com | 301 | https://example.com/ |
http://www.example.com | 301 | https://www.example.com/ |
http://www.example.com/news | 301 | https://www.example.com/news |
http://www.example.com/?id=1 | 301 | https://www.example.com/?id=1 |
http://example.com/news?id=1 | 301 | https://example.com/news?id=1 |
https://example.com | 200 | no redirect |
https://www.example.com | 200 | no redirect |
http
to https
(using HTTP/2 protocol) to hostname example.com
using the HTTP status code 307
("307 Temporary Redirect")const fs = require('fs');
const http = require('http');
const http2 = require('http2');
const Koa = require('koa');
const forceHTTPS = require('koa-force-https');
const options = {
key: fs.readFileSync('ssl-certificate.key'),
cert: fs.readFileSync('ssl-certificate.crt')
}
const app = new Koa();
app.use(forceHTTPS(undefined, 'example.com', 307));
app.use((ctx) => {
ctx.body = 'Hello! This is an HTTPS connection using HTTP/2 protocol.';
});
http.createServer(app.callback()).listen(80);
http2.createSecureServer(options, app.callback()).listen(443);
Request URL | Status Code | Location |
---|---|---|
http://example.com | 307 | https://example.com/ |
http://www.example.com | 307 | https://example.com/ |
http://www.example.com/news | 307 | https://example.com/news |
http://www.example.com/?id=1 | 307 | https://example.com/?id=1 |
http://example.com/news?id=1 | 307 | https://example.com/news?id=1 |
https://example.com | 200 | no redirect |
https://www.example.com | 200 | no redirect |
koa-force-https
is MIT licensed.
FAQs
Koa.js middleware to force HTTPS connection on any incoming requests
The npm package koa-force-https receives a total of 2 weekly downloads. As such, koa-force-https popularity was classified as not popular.
We found that koa-force-https demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.