Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@solayao/koa-server-kit

Latest version: v0.1.4

Overview

Last scanned
27 Nov 2026
Published
27 Nov 2026
npm package Publisher: solayao
6 Versions

Scan summary

@solayao/koa-server-kit was last scanned on 27 Nov 2026 at version 0.1.4. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 6 versions; the latest 5 were published within 2 days (26 and 27 Nov 2026).
  • Findings: No rules fired in version 0.1.4.

Versions

6 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.1.4 LATEST 27 Nov 2026 No rules fired
0.1.3 26 Nov 2026 No rules fired
0.1.2 26 Nov 2026 No rules fired
0.1.1 26 Nov 2026 Not shown
0.1.0 26 Nov 2026 Not shown

No rules fired in 0.1.4

Findings

Findings for v0.1.4. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.1.4; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

@solayao/koa-server-kit

Koa2 服务通用骨架包,内置插件加载、全局中间件、动态路由、Swagger、鉴权、HTTP/HTTPS/TCP 代理、请求中断、自签证书、进程收尾、默认配置与常用工具。

一次 createApiServer 调用即可启动完整服务骨架,宿主只需提供业务配置与业务文件。启动失败由内核统一记录日志并退出(可用 options.exitOnFatalError = false 改为抛出异常交由宿主处理)。

包内已注册通用路由:/public/internal/token(平台 token 换取)、/public/mock/test、/public/api/abort,以及开发环境下的 /public/mock/login。宿主在自己的 routesDir 中声明同方法同路径的路由即可覆盖。

宿主项目仍需提供:

  • .env / gulpfile.js / pm2-control.js
  • routes/* 业务接口
  • jobs/* 定时任务
  • WebDAV 业务目录与字体
  • 自定义启动检查逻辑

安装

npm install @solayao/koa-server-kit

环境变量

源码直接读取的环境变量共 12 项,完整示例与逐项说明见 .env.example。kit 本身不加载 .env,需由宿主入口或部署平台注入。

变量 用途
NODE_ENV 运行模式,影响日志、错误堆栈、JWT 密钥兜底与 SSL 策略
npm_lifecycle_event npm 自动注入,用于开发链路退出时结束父进程
APP_JWT_SECRET JWT 签名密钥,生产环境必需(或提供 jwtSecret.key)
APP_PLATFORM_AUTH_PASS_KEY 内置 /public/internal/token 的共享密钥
APP_INTERNAL_ALLOW_IPS 内置 token 接口额外放行的内网 IP
APP_DOCKER_IP 覆盖对外 IP,用于自签证书 SAN、CORS 与启动日志
APP_ALLOW_INSECURE_SSL 自签证书校验放行开关
APP_INSECURE_ALLOW_LIST 额外跳过证书校验的 IP / CIDR / 域名白名单
APP_CUID_MYSQL 写库 MySQL 连接串
APP_READ_ONLY_MYSQL 只读 MySQL 连接串
APP_ONE_REDIS 单机 Redis 连接串
APP_SENTINEL_REDIS 哨兵 Redis 连接串

快速启动

import Koa from 'koa'
import path from 'path'
import { fileURLToPath } from 'url'
import { createApiServer } from '@solayao/koa-server-kit'

const app = new Koa()

const { server } = await createApiServer({
  app,
  options: {
    routesDir: path.join(path.dirname(fileURLToPath(import.meta.url)), 'src/routes'),
    staticDir: path.join(process.cwd(), 'assets'),
    packageMeta: {
      name: 'my-api',
      title: 'My API',
      version: '1.0.0',
      description: '业务服务'
    },
    isDev: process.env.NODE_ENV !== 'production'
  },
  config: {
    SYSTEM: {
      API_SERVER_PORT: '16333',
      API_BASE_URL: '/schedule',
      USE_MYSQL: true
    }
  },
  adapters: {
    onServerStart: async ({ port, httpPort, httpsPort, pems, currentIps }) => {
      // 启动后的检查、数据库等待、任务初始化
      console.log('服务已启动', { port, httpPort, httpsPort, currentIps })
    },
    cleanup: [
      async () => {
        // 退出时释放资源,如 mysql.end() / redis.quit() / WebDAV agent 关闭
      }
    ]
  }
})

console.log(server.ports)

packageMeta 同时用于默认自签证书的 CN;包内自动从 getCurrentIps() 里筛选合法 IP 作为证书 IP SAN(localhost 由证书内置的 DNS SAN 覆盖),宿主无需再自行调用 createSelfSignedCert 并传 certProvider。需要自定义证书来源时通过 adapters.certProvider 整体覆盖,签名为 (certIps) => Promise<{ private, cert }>,入参已过滤为合法 IP。

createApiServer 内部顺序:

config 一次性注入 → pluginLoader → middleware → routes → routeAbort → server → signalHandler

配置

业务私有配置在 createApiServer 的顶层 config 一次声明,包内合并到默认配置单例。业务代码直接导入取值,覆盖项自动生效,无需每次传参:

import config from '@solayao/koa-server-kit/config'

const SYSTEM = config.solGetConfig('SYSTEM') // 默认配置 + createApiServer 的 config 覆盖

配置在首次调用 createApiServer 时注入并冻结:重复注入会抛错,运行期也无法通过 import config 改写。solGetConfig(key) 只接收配置名,未知 key 直接抛错。

options 负责运行时参数,adapters 负责能力注入,config 负责配置覆盖,三者职责互不重叠。

包内自动设置 app.proxy = true:TCP 代理把真实客户端 IP 写入 X-Forwarded-For,Koa 原生 ctx.ip / ctx.ips 据此取到真实来源,而不是内部代理地址,IP 限流与依赖 ctx.ip 的业务因此准确。

请求中断已内置:监听 route_login / route_abort / route_logout,/public/api/abort 可直接中断带 rk 请求头的在途请求,无需宿主注册。

宿主项目需要提供的文件

src/
├── routes/                  # 业务路由目录,传给 options.routesDir
├── schedules/               # 业务任务,不属于本包
├── plugins/                 # 可选外部插件目录
└── app.js                   # 调用 createApiServer 的入口

路由文件默认导出对象或数组:

export default {
  method: 'get',
  url: '/mock/test',
  useAuth: false,
  useRequestCache: false,
  cb: async (ctx, userInfo) => ({
    code: 200,
    error: '',
    result: { userInfo }
  })
}

约定:

  • useAuth: false → /public${url}
  • useAuth: true → ${apiBaseUrl}${url}
  • 业务方法字段为 cb,兼容 handler
  • 平台 token 带 isPlatform 时禁止访问 ${apiBaseUrl}/ 下的管理接口

主要配置

config(顶层参数)

结构与包内默认配置一致(SYSTEM / CUID_MYSQL / READ_ONLY_MYSQL / ONE_REDIS / SENTINEL_REDIS)。只在启动时声明一次,后续 solGetConfig 自动带上。监听端口与路由前缀也从这里读取:SYSTEM.API_SERVER_PORT、SYSTEM.API_BASE_URL,不要写进 options。

options
参数 默认值 说明
routesDir 必填 路由目录绝对路径
isDev false 开发环境标识,控制 /public/mock 是否免鉴权
packageMeta {} Swagger、启动日志与默认自签证书 CN 的元信息
staticDir / staticDirs 无 静态资源目录,挂载前缀固定为 assets
useRouteCache false 启用路由缓存,需同时注入 cacheGet/cacheSet
certOptions {} 自签证书缓存路径、CA 属性等,仅作用于内置证书提供者
logger 内置 LogColor 需含 error 方法(可选 info/log);不传或传空对象回退到内置默认
internalTokenPath /public/internal/token 内部 token 接口路径,该路径限流单独收紧
internalTokenRateLimitMax 10 内部 token 接口每分钟请求上限
rateLimitMax 300 普通接口每分钟请求上限
jsonLimit / formLimit / textLimit 10mb koa-body 各类型请求体大小上限
uploadTmpDir cwd/assets/uploads/tmp multipart 上传临时目录,启动时自动创建
jwtUnless 内置规则 (ctx) => boolean,覆盖 JWT 免鉴权判断;默认放行 OPTIONS、/swagger、/public(/public/mock 仅开发环境)
exitOnFatalError true 启动失败时由内核记录并 process.exit(1);设为 false 则抛出给宿主
lclCtx {} 额外注入到 ctx 的宿主全局对象(如 $webdav、$isDev)

currentIps 无需配置:包内自适应生成为 [getIPAddress(), '127.0.0.1', 'localhost'](Docker 环境可用 APP_DOCKER_IP 指定),同时用于 ctx.$ips、自签证书 SAN 和启动日志;其中只有合法 IP 会写入证书 IP SAN。

logger 也非必填:默认使用内置 tools/LogColor.js(开发环境彩色控制台、生产环境写 log4js 文件),宿主可传自己的 logger 覆盖。

adapters
参数 说明
pluginLoader () => Promise<pluginContext>,通常传 createPluginLoader()
cacheGet (keys) => Promise<Array>,传入 [passKey, failKey];仅 useRouteCache 开启时需要
cacheSet (key, ttlMs, value) => Promise<void>;仅 useRouteCache 开启时需要
certProvider (certIps) => Promise<{ private, cert }>,传入后覆盖内置默认(默认用 packageMeta + 自适应合法 IP 生成)
logger 路径日志中间件,传了则整体替换默认的 solLogKoaRoute()
onServerStart 服务启动后的初始化逻辑,入参 { port, httpPort, httpsPort, pems, currentIps }
cleanup 进程退出时要执行的资源清理回调

子路径

需要单独使用某个能力时再按子路径导入:

子路径 源码 用途
@solayao/koa-server-kit src/index.js 聚合导出,推荐日常使用
@solayao/koa-server-kit/server src/server/index.js ServerLoader、自签证书、退出收尾、请求中断
@solayao/koa-server-kit/routes src/routes/index.js 动态路由、Swagger、缓存与鉴权拦截
@solayao/koa-server-kit/middleware src/middleware/index.js 全局中间件与错误捕获
@solayao/koa-server-kit/auth src/auth/index.js JWT、平台 token 客户端
@solayao/koa-server-kit/config src/config.js 默认配置、配置继承与 solGetConfig
@solayao/koa-server-kit/plugins src/plugins/index.js 插件扫描与 ctx 注入
@solayao/koa-server-kit/tools src/tools/index.js 通用工具函数

源码跳转

  • IDE 中 Ctrl/Cmd + 点击 导入路径可跳到 node_modules/@solayao/koa-server-kit/src/...
  • 上表源码链接在 VS Code Markdown / GitHub 可点击
  • 发布到 npm 后如需在 npmjs 页面点击,需要补充真实 repository.url

后续拆分

  • @solayao/schedule-kit:调度内核
  • @solayao/webdav-file-kit:WebDAV 文件原语

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @solayao/koa-server-kit

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Ethersphere Hijacked With Crypto Stealing Malware (1)
npm

Ethersphere Hijacked With Crypto Stealing Malware Via Github & npm

Vulnerability Insights

Compromised Claude Code extensions (versions 2.1.312 & 2.1.313) in Cursor try to install a backdoor

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Vulnerability Insights

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?

Frame 2085668439 (1)
Group 1261154229