MoonBit native Content-Security-Policy parser, auditor and migration planner.
LH-DD-lh/csp-weaver-mbtmoon add LH-DD-lh/csp-weaver-mbtimport {
"LH-DD-lh/csp-weaver-mbt" @csp,
}fn main {
let policy = @csp.parse(
"default-src 'self'; script-src 'self' 'nonce-demo'; object-src 'none'",
)
let decision = @csp.allows(
policy,
@csp.script_request("https://app.example/main.js", "https://app.example"),
)
println(decision.reason)
println(@csp.findings_text(@csp.extended_audit(policy)))
}moon check --deny-warn
moon build
moon test --deny-warn
moon run cmd/main
moon publish --dry-run| API | 说明 |
|---|---|
| parse(input) | 解析 CSP 字符串 |
| normalize(policy) | 规范化导出 CSP |
| allows(policy, request) | 模拟资源请求是否允许 |
| audit(policy) | 默认审计 |
| extended_audit(policy) | 扩展审计目录 |
| findings_text(findings) | 渲染审计结果 |
| plan_from_requests(requests) | 从资源请求生成迁移计划 |
| recipe_names() | 返回策略配方名称 |
| recipe_policy_by_name(name) | 按名称获取配方策略 |
| catalog_rule_count() | 返回扩展审计规则数量 |
moon check --deny-warn
moon build
moon test --deny-warn
moon run cmd/main
moon publish --dry-run
git status --short
git rev-list --count HEADmoon login
moon publish --dry-run
moon publishhttps://mooncakes.io/docs/LH-DD-lh/csp-weaver-mbt
https://mooncakes.io/api/v0/manifest/LH-DD-lh/csp-weaver-mbtpub(all) struct ResourceRequest {
kind : ResourceKind
url : String
origin : String
nonce : String
is_inline : Bool
} derive(Eq, Debug)pub(all) struct Source {
raw : String
kind : SourceKind
value : String
line : Int
} derive(Eq, Debug)fn catalog_rule_count() -> Intfn recipe_admin_console_with_legacy_report() -> Stringfn recipe_admin_console_with_navigation() -> Stringfn recipe_admin_console_with_trusted_types() -> Stringfn recipe_analytics_light_with_legacy_report() -> Stringfn recipe_analytics_light_with_navigation() -> Stringfn recipe_analytics_light_with_trusted_types() -> Stringfn recipe_docs_site_with_navigation() -> Stringfn recipe_embed_widget_with_navigation() -> Stringfn recipe_media_gallery_with_legacy_report() -> Stringfn recipe_media_gallery_with_navigation() -> Stringfn recipe_media_gallery_with_trusted_types() -> Stringfn recipe_payment_redirect_with_legacy_report() -> Stringfn recipe_payment_redirect_with_navigation() -> Stringfn recipe_payment_redirect_with_trusted_types() -> Stringfn recipe_report_only_baseline_locked_forms() -> Stringfn recipe_report_only_baseline_with_legacy_report() -> Stringfn recipe_report_only_baseline_with_manifest() -> Stringfn recipe_report_only_baseline_with_navigation() -> Stringfn recipe_report_only_baseline_with_prefetch() -> Stringfn recipe_report_only_baseline_with_reports() -> Stringfn recipe_report_only_baseline_with_trusted_types() -> Stringfn recipe_report_only_baseline_with_upgrade() -> Stringfn recipe_static_site_with_navigation() -> Stringfn recipe_strict_nonce_with_navigation() -> Stringfn recipe_wasm_app_with_navigation() -> StringMoonBit native Content-Security-Policy parser, auditor and migration planner.