]> git.codecow.com Git - libnemo.git/commitdiff
Upgrade HTTP but otherwise reject non-HTTPS RPC URLs.
authorChris Duncan <chris@codecow.com>
Mon, 10 Aug 2026 03:39:11 +0000 (20:39 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 10 Aug 2026 03:39:11 +0000 (20:39 -0700)
src/lib/rpc/index.ts

index 1b5cb46aa2e8d7c08b60d261b37e3ce45791941c..98347001eb5b7b901e73f554023c17eccb9c8d48 100644 (file)
@@ -34,12 +34,21 @@ export class Rpc {
         */
        constructor (url: string | URL, auth?: { header: string, value: string })
        constructor (url: unknown, auth: unknown) {
-               if ((typeof url === 'string' || url instanceof URL) && URL.canParse(url)) {
-                       this.#url = new URL(url)
-                       this.#url.protocol = 'https:'
-               } else {
-                       throw new RpcError('Invalid URL', { cause: url })
+               if (typeof url !== 'string' && !(url instanceof URL)) {
+                       throw new RpcError('Invalid RPC URL', { cause: url })
                }
+               if (!(URL.canParse(url))) {
+                       throw new RpcError('Failed to parse RPC URL', { cause: url })
+               }
+
+               const u = new URL(url)
+               if (u.protocol === 'http:') {
+                       u.protocol = 'https:'
+               }
+               if (u.protocol !== 'https:') {
+                       throw new RpcError('RPC requires HTTPS')
+               }
+               this.#url = u
 
                if (typeof auth === 'string') {
                        (auth as string) = auth.trim()