@lvl99dotcom/edaha-plugin-sftp 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,7 @@ publish:
13
13
  serverUrl: "sftp.example.com"
14
14
  port: 22
15
15
  username: "deploy"
16
+ hostKeyFingerprint: "SHA256:REPLACE_WITH_VERIFIED_SERVER_FINGERPRINT"
16
17
  password:
17
18
  env: "EDAHA_SFTP_PASSWORD"
18
19
  path: "/srv/www"
@@ -21,4 +22,8 @@ publish:
21
22
 
22
23
  The publisher runs through the edaha.md CLI or editor backend. Credentials are resolved server-side and are not sent to the browser.
23
24
 
25
+ Set `hostKeyFingerprint` to the server's OpenSSH SHA256 fingerprint, obtained and verified through a trusted channel. For example, an administrator can use `ssh-keygen -lf /path/to/ssh_host_ed25519_key.pub -E sha256` on the server and provide the fingerprint securely. The publisher checks the host key on every connection and rejects mismatches before authenticating. Invalid fingerprints fail before connecting.
26
+
27
+ For compatibility, omitting the fingerprint does **not** verify the server and can expose credentials to an impostor. Applications that require verification must reject missing fingerprints and publishers without the `hostKeyFingerprintSupported === true` property at publish time; package names alone do not prove a site-installed plugin supports it.
28
+
24
29
  `concurrentUploads` sets the maximum simultaneous SFTP connections. It must be a positive integer and defaults to `5`; set it to `1` for sequential uploads. The server must allow the configured number of connections.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import type { PublisherPlugin } from "@lvl99dotcom/edaha.md/publishing";
2
- export declare const sftp: PublisherPlugin;
2
+ /** An SFTP publisher that verifies configured SHA256 host-key fingerprints */
3
+ export interface SftpPublisherPlugin extends PublisherPlugin {
4
+ readonly hostKeyFingerprintSupported: true;
5
+ }
6
+ export declare const sftp: SftpPublisherPlugin;
3
7
  export default sftp;
package/dist/index.js CHANGED
@@ -1,5 +1,20 @@
1
1
  import { posix } from "node:path";
2
+ import { createHash, timingSafeEqual } from "node:crypto";
2
3
  import Client from "ssh2-sftp-client";
4
+ /** Validate and decode an OpenSSH SHA256 host-key fingerprint */
5
+ const hostKeyFingerprint = (value) => {
6
+ if (value === undefined)
7
+ return undefined;
8
+ if (typeof value === "string" && /^SHA256:[A-Za-z0-9+/]{43}$/.test(value)) {
9
+ const encoded = value.slice(7);
10
+ const decoded = Buffer.from(encoded, "base64");
11
+ if (decoded.length === 32 &&
12
+ decoded.toString("base64url") ===
13
+ encoded.replace(/\+/g, "-").replace(/\//g, "_"))
14
+ return decoded;
15
+ }
16
+ throw new Error('"hostKeyFingerprint" must be an OpenSSH SHA256 fingerprint');
17
+ };
3
18
  /** Read the configured maximum number of concurrent uploads */
4
19
  const concurrentUploads = ({ config }) => {
5
20
  const value = config.concurrentUploads;
@@ -14,6 +29,7 @@ const state = (context) => context.sftp;
14
29
  export const sftp = {
15
30
  name: "SFTP",
16
31
  packageName: "@lvl99dotcom/edaha-plugin-sftp",
32
+ hostKeyFingerprintSupported: true,
17
33
  description: "Publish generated site files to an SFTP server.",
18
34
  options: {
19
35
  serverUrl: {
@@ -41,6 +57,11 @@ export const sftp = {
41
57
  type: "string",
42
58
  $edahaField: { text: true },
43
59
  },
60
+ hostKeyFingerprint: {
61
+ title: "SSH host-key fingerprint (SHA256)",
62
+ type: "string",
63
+ $edahaField: { text: true },
64
+ },
44
65
  path: {
45
66
  title: "Output path",
46
67
  type: "string",
@@ -57,6 +78,7 @@ export const sftp = {
57
78
  concurrency: concurrentUploads,
58
79
  beforeAll: async (_items, context, workerCount = 1) => {
59
80
  const config = context.config;
81
+ const fingerprint = hostKeyFingerprint(config.hostKeyFingerprint);
60
82
  const serverUrl = String(config.serverUrl ?? "");
61
83
  context.sftp = {
62
84
  clients: [],
@@ -77,6 +99,9 @@ export const sftp = {
77
99
  username: String(config.username ?? ""),
78
100
  password: config.password === undefined ? undefined : String(config.password),
79
101
  privateKey,
102
+ ...(fingerprint && {
103
+ hostVerifier: (key) => timingSafeEqual(createHash("sha256").update(key).digest(), fingerprint),
104
+ }),
80
105
  });
81
106
  }
82
107
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvl99dotcom/edaha-plugin-sftp",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Publish edaha.md sites to SFTP servers.",
5
5
  "keywords": [
6
6
  "edaha.md",
@@ -41,10 +41,10 @@
41
41
  "ssh2-sftp-client": "^12.0.1"
42
42
  },
43
43
  "peerDependencies": {
44
- "@lvl99dotcom/edaha.md": "^0.9.0"
44
+ "@lvl99dotcom/edaha.md": "^0.9.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@lvl99dotcom/edaha.md": "^0.9.0",
47
+ "@lvl99dotcom/edaha.md": "^0.9.2",
48
48
  "@types/ssh2-sftp-client": "^9.0.4"
49
49
  },
50
50
  "scripts": {