Skip to content

Security: add hardening module and secure-bot extension#7346

Closed
AlphonseC wants to merge 3 commits intoopenclaw:mainfrom
AlphonseC:claude/security-analysis-ai-bot-NdOjG
Closed

Security: add hardening module and secure-bot extension#7346
AlphonseC wants to merge 3 commits intoopenclaw:mainfrom
AlphonseC:claude/security-analysis-ai-bot-NdOjG

Conversation

@AlphonseC
Copy link

@AlphonseC AlphonseC commented Feb 2, 2026

  • Add src/security/hardening.ts with comprehensive security utilities:

    • Cryptographically secure token generation
    • Input validation and sanitization
    • Path traversal prevention
    • File permission hardening
    • Rate limiting implementation
    • Security headers helper
    • Audit logging utilities
  • Add extensions/secure-bot with AI bot security features:

    • Prompt injection detection with 20+ patterns
    • Access control lists (allow/block/admin)
    • Rate limiting per user
    • Sensitive data redaction (PII, API keys)
    • Security event logging and metrics
    • Configurable security policies
  • Add comprehensive test suite for hardening module

https://claude.ai/code/session_0152DnGhhwvDXMppXwT6dtPz

Greptile Overview

Greptile Summary

Adds a new src/security/hardening.ts module with helpers for token generation, input/path validation, file permission hardening, config hardening/auditing, a simple in-memory rate limiter, and recommended HTTP security headers, along with a Vitest test suite.

Also introduces a new workspace extension package @openclaw/secure-bot implementing a channel plugin that applies access control, rate limiting, prompt-injection pattern detection, and redaction to inbound/outbound messages, plus basic schema/defaults for configuration.

Confidence Score: 2/5

  • This PR is not safe to merge as-is due to a runtime ESM/CJS incompatibility and likely plugin packaging issues.
  • The new sanitizePath uses require() inside an ESM TS module, which will throw at runtime when invoked. Separately, the @openclaw/secure-bot package is configured to publish dist/ but does not build or include compiled output, and plugin installs omit devDependencies, so the extension is likely non-functional when installed normally. Other issues are lower severity (duplicate exports, potentially broken docs link).
  • src/security/hardening.ts; extensions/secure-bot/package.json; extensions/secure-bot/src/index.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

- Add src/security/hardening.ts with comprehensive security utilities:
  - Cryptographically secure token generation
  - Input validation and sanitization
  - Path traversal prevention
  - File permission hardening
  - Rate limiting implementation
  - Security headers helper
  - Audit logging utilities

- Add extensions/secure-bot with AI bot security features:
  - Prompt injection detection with 20+ patterns
  - Access control lists (allow/block/admin)
  - Rate limiting per user
  - Sensitive data redaction (PII, API keys)
  - Security event logging and metrics
  - Configurable security policies

- Add comprehensive test suite for hardening module

https://claude.ai/code/session_0152DnGhhwvDXMppXwT6dtPz
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +226 to +228
export function sanitizePath(inputPath: string, baseDir: string): string | null {
const path = require("node:path");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] sanitizePath uses CommonJS require() in an ESM TypeScript module.

In this repo, src/**/*.ts is ESM (import ... from "node:path"), so require("node:path") will throw at runtime in ESM contexts. This will break any code path that calls sanitizePath.

Suggested change
export function sanitizePath(inputPath: string, baseDir: string): string | null {
const path = require("node:path");
import * as path from "node:path";
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/security/hardening.ts
Line: 226:228

Comment:
[P0] `sanitizePath` uses CommonJS `require()` in an ESM TypeScript module.

In this repo, `src/**/*.ts` is ESM (`import ... from "node:path"`), so `require("node:path")` will throw at runtime in ESM contexts. This will break any code path that calls `sanitizePath`.

```suggestion
  import * as path from "node:path";
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +27 to +36
"license": "MIT",
"peerDependencies": {
"openclaw": "*"
},
"devDependencies": {
"openclaw": "workspace:*",
"typescript": "^5.3.0",
"vitest": "^1.0.0"
},
"files": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Plugin install will omit devDependencies, but typescript/vitest are only in devDependencies and there is no dist/ committed.

Per repo guidelines, plugin installs run npm install --omit=dev in the extension dir. With the current files: ["dist", ...] and no build-on-install script, a published package will ship without compiled JS and can't run. Either ship prebuilt dist in the published tarball or move any runtime-required deps/scripts accordingly.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/secure-bot/package.json
Line: 27:36

Comment:
[P0] Plugin install will omit `devDependencies`, but `typescript`/`vitest` are only in `devDependencies` and there is no `dist/` committed.

Per repo guidelines, plugin installs run `npm install --omit=dev` in the extension dir. With the current `files: ["dist", ...]` and no build-on-install script, a published package will ship without compiled JS and can't run. Either ship prebuilt `dist` in the published tarball or move any runtime-required deps/scripts accordingly.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +669 to +675
// Export security engine for direct access
export { SecurityEngine, securityEngine, DEFAULT_CONFIG };

// Export types
export type { SecureBotConfig, SecurityEvent, SecurityEventType, SecurityMetrics };

export default plugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Duplicate exports for the same types.

SecureBotConfig, SecurityEvent, SecurityEventType, and SecurityMetrics are already exported as export type ... where they are declared, then re-exported again at the bottom. This tends to trip linting/TS settings (duplicate export) and makes the public surface harder to reason about.

Also appears in the same file for other already-exported items: DEFAULT_CONFIG is exported twice (const + re-export).

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/secure-bot/src/index.ts
Line: 669:675

Comment:
[P1] Duplicate exports for the same types.

`SecureBotConfig`, `SecurityEvent`, `SecurityEventType`, and `SecurityMetrics` are already exported as `export type ...` where they are declared, then re-exported again at the bottom. This tends to trip linting/TS settings (duplicate export) and makes the public surface harder to reason about.

Also appears in the same file for other already-exported items: `DEFAULT_CONFIG` is exported twice (const + re-export).

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +555 to +562
const meta: ChannelMeta = {
id: "secure-bot",
label: "Secure Bot",
description: "Security-hardened AI bot with enhanced protection features",
emoji: "🛡️",
color: "#4CAF50",
docs: "https://docs.openclaw.ai/extensions/secure-bot",
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Hardcoded docs URL likely wrong.

meta.docs points to https://docs.openclaw.ai/extensions/secure-bot, but the README and repo don't add the corresponding docs page in this PR. If this page doesn't exist, the in-product docs link will be broken for users.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/secure-bot/src/index.ts
Line: 555:562

Comment:
[P1] Hardcoded docs URL likely wrong.

`meta.docs` points to `https://docs.openclaw.ai/extensions/secure-bot`, but the README and repo don't add the corresponding docs page in this PR. If this page doesn't exist, the in-product docs link will be broken for users.

How can I resolve this? If you propose a fix, please make it concise.

新增資安漏洞修復模組,涵蓋 Top 10 漏洞:

1. Gateway 暴露於 0.0.0.0:18789
   - 自動產生安全 token
   - 強制 loopback 綁定

2. DM policy 允許所有使用者
   - 偵測 open policy
   - 自動切換為 allowlist

3. Sandbox 預設停用
   - 啟用完整沙箱模式
   - Docker 網路隔離

4. Credentials 明文儲存
   - 強制 600/700 權限
   - 目錄安全檢查

5. Prompt injection 透過 web content
   - 20+ 注入模式偵測
   - 自動包裝不信任內容

6. 危險命令未封鎖
   - rm -rf, curl|sh 等封鎖清單
   - 命令安全檢查函式

7. 無網路隔離
   - Docker network=none
   - 移除 DNS/extraHosts

8. 過高工具存取權限
   - 最小權限建議
   - 工具白名單

9. 無稽核日誌
   - 啟用日誌遮蔽
   - Session 記錄建議

10. 弱配對碼
    - 12 字元安全碼
    - 移除易混淆字元

https://claude.ai/code/session_0152DnGhhwvDXMppXwT6dtPz
新增 Python 依賴檔案,用於:
- 整合 OpenClaw Gateway API
- 自動化安全稽核腳本
- WebSocket 客戶端連接

https://claude.ai/code/session_0152DnGhhwvDXMppXwT6dtPz
@openclaw-barnacle
Copy link

Please make this as a third-party plugin that you maintain yourself in your own repo. Docs: https://docs.openclaw.ai/plugin. Feel free to open a PR after to add it to our community plugins page: https://docs.openclaw.ai/plugins/community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants