---
title: Homebrew Formula来源与SHA256治理(Tap-白名单)最佳实践
keywords:
- Homebrew
- Formula
- Tap
- SHA256
- 白名单
description: 对 Homebrew Formula 的来源与 SHA256 校验进行白名单治理,阻断非受控 Tap 与摘要不一致的安装。
categories:
- 文章资讯
- 编程技术
---
实现示例
type Formula = { name: string; url: string; sha256: string; tap: string }
const allowTaps = new Set<string>(['homebrew/core','homebrew/cask','corp/tap'])
function hex64(h: string): boolean { return /^[A-Fa-f0-9]{64}$/.test(h) }
function validUrl(u: string): boolean { try { const x = new URL(u); return x.protocol === 'https:' } catch { return false } }
function tapAllowed(t: string): boolean { return allowTaps.has(t) }
function evaluate(f: Formula): { ok: boolean; errors: string[] } {
const errors: string[] = []
if (!f.name || !validUrl(f.url) || !hex64(f.sha256)) errors.push('entry')
if (!tapAllowed(f.tap)) errors.push('tap')
return { ok: errors.length === 0, errors }
}
审计与运行治理
- 审计 Formula 的 Tap 与来源、哈希;异常阻断并输出修复建议。
- 企业自建 Tap 需审批与归档。

发表评论 取消回复