permscope

    Audit Permissions-Policy browser capability boundaries in MoonBit.

    moonbit
    permissions-policy
    security-headers
    capability-contract
    web-security
    audit
    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    9 hours ago
    Downloads
    17

    #permscope

    MoonBit library for browser capability boundary auditing, with a deep Permissions-Policy parser and route-level capability contracts at its core. Supporting checks for CSP, HSTS, referrer, clickjacking, MIME sniffing, and cross-origin isolation provide response-header context around that core.

    permscope helps small web tools, gateways, static-site checks, and CI scripts answer questions such as:

    • Which browser capabilities does this header allow?
    • Are sensitive features such as camera, microphone, geolocation, payment, USB, serial, HID, or Bluetooth too permissive?
    • Can an old Feature-Policy header be migrated to modern Permissions-Policy syntax?
    • Does a route or component expose only the browser capabilities it declared in its capability contract?
    • Do the response headers satisfy practical web security baselines for CSP, HSTS, referrer leakage, clickjacking, MIME sniffing, and cross-origin isolation?

    #Status

    Initial August Hackathon version by 李明坤. The September work extends this existing project as a community maintenance entry. Version 0.1.1 is available on Mooncakes; 0.1.2 is the next release and must not be described as published until its package page is verified.

    #Features

    • Parse modern Permissions-Policy directives.
    • Parse legacy Feature-Policy headers for migration.
    • Normalize allowlists containing self, *, empty deny lists, and explicit origins.
    • Evaluate whether a browser feature is allowed for a document origin and target origin.
    • Audit high-risk capabilities such as camera, microphone, geolocation, payment, USB, serial, HID, and Bluetooth.
    • Build strict headers from declarative policy intents.
    • Use a built-in browser capability catalog to create recommended policies.
    • Generate built-in profile headers for strict, balanced, media-app, and device-lab deployments.
    • Compare two policies and classify loosened or tightened changes.
    • Summarize how many features are disabled, self-only, wildcard, or delegated to explicit origins.
    • Parse raw HTTP response headers copied from curl -I -L output, auditing only the final response rather than mixing redirect-hop policies.
    • Audit the effective policy from modern and legacy response headers.
    • Render feature/origin access matrices for documentation and reviews.
    • Define route-level capability contracts and audit missing, overbroad, or undeclared Permissions-Policy delegations.
    • Audit an observed route response against its declared capability contract, rejecting absent or malformed modern policy headers and origin mismatches.
    • Compare named route contracts with observed response samples as a CI inventory, reporting missing, undeclared, or duplicate route names.
    • Generate the strictest Permissions-Policy header that satisfies a declared capability contract.
    • Parse and audit core Content-Security-Policy directives.
    • Audit Strict-Transport-Security, Referrer-Policy, X-Frame-Options, X-Content-Type-Options, COOP, COEP, and CORP.
    • Generate strict, static-site, API-service, media-app, and device-lab security header bundles.
    • Score security headers with grades, finding summaries, recommendations, CI gates, and batch reports across multiple routes.
    • Render stable text reports for CI logs or command-line tools.

    #Install

    The latest verified Mooncakes release is 0.1.1:

    moon add LMK-ai-nb/permscope@0.1.1

    Add "LMK-ai-nb/permscope" to the import block of your moon.pkg, then call its functions through @permscope. The September 0.1.2 changes are in this source tree until a release is published and verified.

    #Quick Start

    moon check moon test moon run cmd/main moon run examples/route_contract

    #Example

    let header =
    "camera=(), microphone=(), geolocation=(), fullscreen=(self \"https://video.example\")"
    let policy = @permscope.parse(header)

    let can_use_camera = @permscope.allows(
    policy,
    "camera",
    "https://app.example",
    "https://app.example",
    )

    let report = @permscope.audit(
    policy,
    @permscope.default_baseline("https://app.example"),
    )
    let contract = @permscope.capability_contract(
    "video-room",
    "https://app.example",
    [
    @permscope.capability_need("camera", ["self"], "local preview"),
    @permscope.capability_need(
    "fullscreen",
    ["self", "https://video.example"],
    "embedded player",
    ),
    ],
    true,
    )
    let contract_policy = @permscope.parse(
    @permscope.minimal_policy_for_contract(contract),
    )
    let contract_report = @permscope.audit_capability_contract(
    contract_policy,
    contract,
    )
    println(can_use_camera.to_string())
    println(@permscope.render_report(report))
    println(@permscope.render_capability_contract_report(contract_report))

    Run the bundled demo:

    moon run cmd/main

    For observed responses, run moon run examples/route_contract. This example declares capability needs for /video and /checkout, builds scoped policies, checks synthetic response blocks and document origins, then checks both routes as an inventory. The /video sample includes a redirect whose broad policy must not override the final response. It prints a route=/video audit with sample=video-room, contract: pass, and inventory: pass.

    Expected highlights:

    permscope demo camera cross-site=false effective=permissions-policy permscope access matrix document=https://app.example permscope capability contract contract=video-room score 80/80 percent=100 grade=A permscope batch security audit permscope: pass

    #API Overview

    • parse(header) parses a modern Permissions-Policy header.
    • parse_feature_policy(header) parses old Feature-Policy syntax.
    • migrate_feature_policy(header) renders old syntax as modern syntax.
    • directive(policy, feature) returns the first directive for a feature.
    • allows(policy, feature, document_origin, target_origin) checks whether the supplied header restricts a feature for an origin; it does not model every browser default, iframe policy, or user permission.
    • default_baseline(document_origin) creates a practical web-app security baseline.
    • audit(policy, baseline) reports risky wildcards, missing denies, parse warnings, and insecure origins.
    • deny, self_only, all_origins, self_and_origins, and build create normalized headers from code.
    • known_features, known_feature, recommended_header, and catalog_baseline provide a practical browser capability catalog.
    • built_in_profiles, profile_header, profile_policy, profile_baseline, and render_profile provide deployment-oriented policy presets.
    • capability_contract, capability_need, optional_capability_need, minimal_policy_for_contract, audit_capability_contract, and render_capability_contract_report provide scenario-level capability boundary checks.
    • audit_capability_response(sample, contract) and render_capability_response_audit check an observed route response. This strict path requires a modern Permissions-Policy header; use audit_header_block to inspect legacy Feature-Policy for migration.
    • audit_capability_inventory(samples, contracts) and render_capability_inventory join routes by trimmed name and fail on missing samples, samples without contracts, duplicate names, or failing route audits.
    • summarize and render_summary produce compact dashboard-friendly counts.
    • parse_header_block, permissions_policy_header, feature_policy_header, policy_from_headers, audit_header_block, and render_header_audit work with raw HTTP response header blocks. For multi-response curl -I -L text, only the final HTTP status block contributes headers and parse warnings.
    • access_matrix, matrix_cell, and render_access_matrix explain whether selected features are allowed for selected origins.
    • parse_csp, audit_csp, strict_csp_header, and app_csp_header cover the CSP subset used by common web applications.
    • audit_security_header_block, render_security_audit, render_security_markdown, render_security_json, security_recommendations, and security_gate provide full response-header scoring and CI output.
    • strict_security_bundle, static_site_security_bundle, api_service_security_bundle, media_security_bundle, and device_lab_security_bundle generate reusable deployment presets.
    • audit_response_samples, render_batch_audit, render_batch_markdown, render_batch_json, and batch_security_gate support multi-route checks.
    • diff and render_diffs show feature-level policy changes.
    • render(policy) and render_report(report) produce stable text output.

    #Development

    The current CI uses MoonBit moonc v0.10.14. The root package disables only the implicit_impl_as_method migration warning emitted for existing derived Eq and Debug implementations; all other enabled warnings remain fatal in the strict checks below.

    moon fmt --check moon check --deny-warn moon build moon test --deny-warn moon test --target js --deny-warn moon info moon run cmd/main moon run examples/route_contract

    The GitHub Actions workflow runs the same checks on every push and pull request. Generated pkg.generated.mbti files document the public MoonBit API.

    #Publishing

    The package name, repository, license, README, and version are defined in moon.mod. After validating the release candidate and syncing its source to the public default branch, inspect the package contents and publish with:

    moon package --list moon whoami moon publish --frozen

    Publishing needs the Mooncakes account authorized for the LMK-ai-nb namespace. Verify the resulting version on Mooncakes before recording it as published. See release checklist.

    #Project Boundary

    permscope is intentionally a browser capability policy library. It can parse response header text that a caller already has, but it does not make HTTP requests, start a web server, or depend on a browser runtime. Host applications can use it inside a gateway, static analysis tool, CI check, documentation generator, or web framework adapter.

    The project does not audit mooncakes.io publishing status, does not verify README example provenance, does not implement robots.txt policy, and is not a general contest review proof tool. Its core boundary is Permissions-Policy capability exposure: parsing, legacy migration, origin decisions, feature catalogs, access matrices, policy diffs, and capability contracts. Broader security-header scoring is supporting context for that capability workflow. The parser is a focused audit aid, not a browser implementation or a substitute for deployment testing. It does not fetch live URLs. Callers supply observed response headers and should verify browser-specific enforcement separately. For redirected URLs, pass the complete curl -I -L header output and the final document origin; permscope cannot infer that origin from headers.

    #License

    Apache-2.0. This repository does not vendor third-party source code, fixtures, or media assets. See source and AI use, design notes, test record, and the September application.

    AccessCell

    pub struct AccessCell {
    feature : String
    target_origin : String
    allowed : Bool
    } derive(Eq,
    Debug
    )

    One feature/origin access decision in a matrix report.

    AccessMatrix

    pub struct AccessMatrix {
    document_origin : String
    features : Array[String]
    target_origins : Array[String]
    cells : Array[AccessCell]
    } derive(Eq,
    Debug
    )

    Matrix view of many features across many target origins.

    AllowToken

    pub enum AllowToken {
    TokenSelf
    TokenAll
    TokenOrigin(String)
    } derive(Eq,
    Debug
    )

    One Permissions-Policy allowlist token.

    AuditReport

    pub struct AuditReport {
    ok : Bool
    findings : Array[Finding]
    } derive(Eq,
    Debug
    )

    Result of auditing a parsed policy against a baseline.

    Baseline

    pub struct Baseline {
    document_origin : String
    sensitive_features : Array[String]
    deny_by_default : Array[String]
    } derive(Eq,
    Debug
    )

    Project-specific security expectations.

    BaselineProfile

    pub enum BaselineProfile {
    ProfileStrict
    ProfileBalanced
    ProfileMediaApp
    ProfileDeviceLab
    } derive(Eq,
    Debug
    )

    Built-in policy profiles for common web application shapes.

    BatchAudit

    pub struct BatchAudit {
    samples : Array[ResponseSample]
    audits : Array[SecurityAudit]
    scores : Array[SampleScore]
    average_percent : Int
    worst_grade : String
    high_total : Int
    warning_total : Int
    } derive(Eq,
    Debug
    )

    Batch audit across many response samples.

    BatchGate

    pub struct BatchGate {
    ok : Bool
    required_grade : String
    max_high : Int
    max_warning : Int
    messages : Array[String]
    } derive(Eq,
    Debug
    )

    Batch-level CI gate result.

    BatchRecommendation

    pub struct BatchRecommendation {
    sample : String
    path : String
    header : String
    value : String
    priority : String
    reason : String
    } derive(Eq,
    Debug
    )

    One batch recommendation tied to a response sample.

    CapabilityContract

    pub struct CapabilityContract {
    name : String
    document_origin : String
    needs : Array[CapabilityNeed]
    forbid_unspecified : Bool
    } derive(Eq,
    Debug
    )

    A scenario-specific contract for browser capabilities.

    CapabilityContractReport

    pub struct CapabilityContractReport {
    contract : CapabilityContract
    ok : Bool
    findings : Array[CapabilityFinding]
    allowed : Int
    missing : Int
    overbroad : Int
    unexpected : Int
    } derive(Eq,
    Debug
    )

    Result of auditing a Permissions-Policy against a capability contract.

    CapabilityFinding

    pub struct CapabilityFinding {
    severity : Severity
    code : String
    feature : String
    target_origin : String
    message : String
    } derive(Eq,
    Debug
    )

    One finding produced while checking a capability contract.

    CapabilityInventoryAudit

    pub struct CapabilityInventoryAudit {
    audits : Array[CapabilityResponseAudit]
    findings : Array[CapabilityInventoryFinding]
    ok : Bool
    } derive(Eq,
    Debug
    )

    Audit of all observed route responses against named capability contracts.

    CapabilityInventoryFinding

    pub struct CapabilityInventoryFinding {
    code : String
    name : String
    message : String
    } derive(Eq,
    Debug
    )

    An inventory-level mismatch between declared routes and observed responses.

    CapabilityNeed

    pub struct CapabilityNeed {
    feature : String
    target_origins : Array[String]
    reason : String
    required : Bool
    } derive(Eq,
    Debug
    )

    One capability needed by a route, component, or user journey.

    CapabilityResponseAudit

    pub struct CapabilityResponseAudit {
    sample : ResponseSample
    report : CapabilityContractReport
    } derive(Eq,
    Debug
    )

    A route's observed response and the result of checking its capability contract.

    ContractCounters

    type ContractCounters derive(Eq,
    Debug
    )

    CspDirective

    pub struct CspDirective {
    name : String
    values : Array[String]
    raw : String
    index : Int
    } derive(Eq,
    Debug
    )

    One parsed Content-Security-Policy directive.

    CspPolicy

    pub struct CspPolicy {
    directives : Array[CspDirective]
    warnings : Array[ParseWarning]
    } derive(Eq,
    Debug
    )

    Parsed Content-Security-Policy header.

    CspSummary

    pub struct CspSummary {
    directive_count : Int
    source_directives : Int
    wildcard_sources : Int
    unsafe_inline : Int
    unsafe_eval : Int
    nonce_sources : Int
    hash_sources : Int
    insecure_sources : Int
    missing_core : Array[String]
    } derive(Eq,
    Debug
    )

    Compact Content-Security-Policy summary.

    DiffKind

    pub enum DiffKind {
    DiffAdded
    DiffRemoved
    DiffChanged
    DiffLoosened
    DiffTightened
    } derive(Eq,
    Debug
    )

    Difference severity between two policies.

    Directive

    pub struct Directive {
    feature : String
    tokens : Array[AllowToken]
    raw : String
    index : Int
    } derive(Eq,
    Debug
    )

    A parsed Permissions-Policy directive such as camera=().

    FeatureCategory

    pub enum FeatureCategory {
    CategorySensors
    CategoryMedia
    CategoryDevice
    CategoryIdentity
    CategoryPayment
    CategoryDisplay
    CategoryStorage
    CategoryExperimental
    CategoryOther
    } derive(Eq,
    Debug
    )

    Browser capability category used by the built-in feature catalog.

    FeatureSpec

    pub struct FeatureSpec {
    feature : String
    category : FeatureCategory
    risk : RiskLevel
    recommended : PolicyIntent
    rationale : String
    } derive(Eq,
    Debug
    )

    Metadata for a known Permissions-Policy feature.

    Finding

    pub struct Finding {
    severity : Severity
    code : String
    feature : String?
    message : String
    } derive(Eq,
    Debug
    )

    One policy audit finding.

    HeaderAudit

    pub struct HeaderAudit {
    headers : HeaderSet
    modern : Policy?
    legacy : Policy?
    effective : Policy
    report : AuditReport
    used_legacy : Bool
    migration : String
    } derive(Eq,
    Debug
    )

    End-to-end audit result for a raw HTTP response header block.

    HeaderCheck

    pub struct HeaderCheck {
    header : String
    present : Bool
    score : Int
    max_score : Int
    findings : Array[Finding]
    observed : String
    recommended : String
    } derive(Eq,
    Debug
    )

    Result of auditing one security header family.

    HeaderKind

    pub enum HeaderKind {
    HeaderPermissionsPolicy
    HeaderFeaturePolicy
    HeaderOther
    } derive(Eq,
    Debug
    )

    Kind of HTTP response header recognized by the header-block parser.

    HeaderLine

    pub struct HeaderLine {
    name : String
    value : String
    index : Int
    kind : HeaderKind
    } derive(Eq,
    Debug
    )

    One parsed HTTP response header line.

    HeaderRecommendation

    pub struct HeaderRecommendation {
    header : String
    value : String
    reason : String
    priority : String
    } derive(Eq,
    Debug
    )

    Human-facing recommendation for a security header.

    HeaderSet

    pub struct HeaderSet {
    lines : Array[HeaderLine]
    warnings : Array[ParseWarning]
    } derive(Eq,
    Debug
    )

    Parsed final HTTP response header block, suitable for curl -I -L output.

    ParseWarning

    pub struct ParseWarning {
    index : Int
    message : String
    text : String
    } derive(Eq,
    Debug
    )

    A non-fatal parser warning. Warnings keep the policy usable in CI reports.

    Policy

    pub struct Policy {
    directives : Array[Directive]
    warnings : Array[ParseWarning]
    } derive(Eq,
    Debug
    )

    Parsed modern Permissions-Policy header.

    PolicyDiff

    pub struct PolicyDiff {
    kind : DiffKind
    feature : String
    before : String?
    after : String?
    } derive(Eq,
    Debug
    )

    One feature-level policy difference.

    PolicyIntent

    pub enum PolicyIntent {
    IntentDeny(String)
    IntentSelf(String)
    IntentAll(String)
    IntentOrigins(String, Array[String])
    IntentOriginsOnly(String, Array[String])
    } derive(Eq,
    Debug
    )

    One mutable builder operation is represented as a value so callers can keep configuration declarative.

    PolicySummary

    pub struct PolicySummary {
    disabled : Int
    self_only : Int
    wildcard : Int
    explicit_origins : Int
    missing_sensitive : Array[String]
    } derive(Eq,
    Debug
    )

    Compact policy summary for dashboards and release notes.

    ResponseSample

    pub struct ResponseSample {
    name : String
    path : String
    document_origin : String
    header_block : String
    } derive(Eq,
    Debug
    )

    One response sample collected from a route, endpoint, or deployment.

    RiskLevel

    pub enum RiskLevel {
    RiskLow
    RiskMedium
    RiskHigh
    } derive(Eq,
    Debug
    )

    Approximate risk tier for a browser capability.

    SampleScore

    pub struct SampleScore {
    name : String
    path : String
    grade : String
    points : Int
    max_points : Int
    percent : Int
    high : Int
    warning : Int
    } derive(Eq,
    Debug
    )

    Score for one audited response sample.

    SecurityAudit

    pub struct SecurityAudit {
    headers : HeaderSet
    csp : CspPolicy?
    permissions : HeaderAudit
    checks : Array[HeaderCheck]
    score : SecurityScore
    } derive(Eq,
    Debug
    )

    Full response security-header audit.

    SecurityCoverage

    pub struct SecurityCoverage {
    required : Int
    present : Int
    strong : Int
    missing : Array[String]
    weak : Array[String]
    } derive(Eq,
    Debug
    )

    Coverage summary for the headers audited by permscope.

    SecurityFindingSummary

    pub struct SecurityFindingSummary {
    total : Int
    high : Int
    warning : Int
    info : Int
    high_codes : Array[String]
    warning_codes : Array[String]
    info_codes : Array[String]
    } derive(Eq,
    Debug
    )

    Summary of findings grouped by severity.

    SecurityGate

    pub struct SecurityGate {
    ok : Bool
    required_grade : String
    actual_grade : String
    allow_warnings : Bool
    messages : Array[String]
    } derive(Eq,
    Debug
    )

    CI-style gate result for a security audit.

    SecurityHeaderBundle

    pub struct SecurityHeaderBundle {
    name : String
    description : String
    document_origin : String
    headers : Array[SecurityHeaderEntry]
    notes : Array[String]
    } derive(Eq,
    Debug
    )

    A reusable security-header bundle for a deployment scenario.

    SecurityHeaderEntry

    pub struct SecurityHeaderEntry {
    name : String
    value : String
    } derive(Eq,
    Debug
    )

    One generated HTTP security header.

    SecurityRegression

    pub struct SecurityRegression {
    header : String
    before_score : Int
    after_score : Int
    delta : Int
    severity : String
    message : String
    } derive(Eq,
    Debug
    )

    One score change between two security audits.

    SecurityScore

    pub struct SecurityScore {
    points : Int
    max_points : Int
    percent : Int
    grade : String
    high : Int
    warning : Int
    info : Int
    } derive(Eq,
    Debug
    )

    Aggregated security score for a response.

    Severity

    pub enum Severity {
    SeverityInfo
    SeverityWarning
    SeverityHigh
    } derive(Eq,
    Debug
    )

    Audit severity used by reports and CI output.

    SourceExpression

    pub struct SourceExpression {
    value : String
    kind : String
    secure : Bool
    wildcard : Bool
    } derive(Eq,
    Debug
    )

    One interpreted CSP source expression.

    access_matrix

    fn access_matrix(policy : Policy, features : Array[String], document_origin : String, target_origins : Array[String]) -> AccessMatrix

    Build a many-feature, many-origin access matrix.

    all_origins

    fn all_origins(feature : String) -> PolicyIntent

    Create an intent that allows a feature for every origin.

    allows

    fn allows(policy : Policy, feature : String, document_origin : String, target_origin : String) -> Bool

    Decide whether a feature is allowed for a target origin.

    Missing directives return true because this header adds no restriction for that feature. This does not assert that a browser will grant access: feature defaults, user permissions, and iframe policies are outside this check. Use audit to flag missing explicit restrictions.

    api_service_security_bundle

    fn api_service_security_bundle(document_origin : String) -> SecurityHeaderBundle

    API service bundle for JSON endpoints and machine clients.

    app_csp_header

    fn app_csp_header(api_origins : Array[String], media_origins : Array[String]) -> String

    Build a CSP for an app that needs selected trusted API and media origins.

    audit

    fn audit(policy : Policy, baseline : Baseline) -> AuditReport

    Audit a parsed policy for risky defaults and overly broad allowlists.

    audit_capability_contract

    fn audit_capability_contract(policy : Policy, contract : CapabilityContract) -> CapabilityContractReport

    Audit whether a policy exactly supports a route-level capability contract.

    audit_capability_inventory

    fn audit_capability_inventory(samples : Array[ResponseSample], contracts : Array[CapabilityContract]) -> CapabilityInventoryAudit

    Check that every named contract has one observed response and every response has one contract. Names are compared after trimming surrounding whitespace.

    audit_capability_response

    fn audit_capability_response(sample : ResponseSample, contract : CapabilityContract) -> CapabilityResponseAudit

    Audit the actual response headers for one declared route.

    This check requires a modern Permissions-Policy header. Legacy Feature-Policy can still be inspected with audit_header_block for migration work.

    audit_csp

    fn audit_csp(policy : CspPolicy) -> AuditReport

    Audit a Content-Security-Policy header.

    audit_header_block

    fn audit_header_block(block : String, baseline : Baseline) -> HeaderAudit

    Audit a raw HTTP response header block.

    audit_response_sample

    fn audit_response_sample(sample : ResponseSample) -> SecurityAudit

    Audit one response sample.

    audit_response_samples

    fn audit_response_samples(samples : Array[ResponseSample]) -> BatchAudit

    Audit many response samples.

    audit_security_bundle

    fn audit_security_bundle(bundle : SecurityHeaderBundle) -> SecurityAudit

    Audit a generated bundle.

    audit_security_header_block

    fn audit_security_header_block(block : String, document_origin : String) -> SecurityAudit

    Audit a raw HTTP response header block for multiple security headers.

    audit_security_headers

    fn audit_security_headers(headers : HeaderSet, document_origin : String) -> SecurityAudit

    Audit parsed HTTP response headers for multiple security headers.

    balanced_profile

    fn balanced_profile() -> BaselineProfile

    Profile that follows the package's default recommendation catalog.

    batch_recommendations

    fn batch_recommendations(batch : BatchAudit) -> Array[BatchRecommendation]

    Collect recommendations across every response sample.

    batch_samples_with_high

    fn batch_samples_with_high(batch : BatchAudit) -> Array[SampleScore]

    Return samples with high-severity findings.

    batch_scores_at_or_below

    fn batch_scores_at_or_below(batch : BatchAudit, grade : String) -> Array[SampleScore]

    Return scores at or below a grade threshold.

    batch_security_gate

    fn batch_security_gate(batch : BatchAudit, required_grade : String, max_high : Int, max_warning : Int) -> BatchGate

    Build a batch gate for CI.

    best_sample_score

    fn best_sample_score(batch : BatchAudit) -> SampleScore?

    Return the best sample score in a batch.

    build

    fn build(intents : Array[PolicyIntent]) -> String

    Build a modern header from declarative feature intents.

    build_policy

    fn build_policy(intents : Array[PolicyIntent]) -> Policy

    Build a policy from declarative feature intents.

    built_in_profiles

    fn built_in_profiles() -> Array[BaselineProfile]

    Return all built-in policy profiles.

    bundle_header_value

    fn bundle_header_value(bundle : SecurityHeaderBundle, name : String) -> String?

    Return the first value for a header in a bundle.

    capability_contract

    fn capability_contract(name : String, document_origin : String, needs : Array[CapabilityNeed], forbid_unspecified : Bool) -> CapabilityContract

    Create a named capability contract.

    capability_contract_features

    fn capability_contract_features(contract : CapabilityContract) -> Array[String]

    Return the declared feature names in stable first-seen order.

    capability_need

    fn capability_need(feature : String, target_origins : Array[String], reason : String) -> CapabilityNeed

    Declare a required browser capability for one or more target origins.

    catalog_baseline

    fn catalog_baseline(document_origin : String) -> Baseline

    Build a baseline from the feature catalog instead of a hard-coded list.

    compare_security_audits

    fn compare_security_audits(before : SecurityAudit, after : SecurityAudit) -> Array[SecurityRegression]

    Compare two audits and return score regressions or improvements.

    csp_allows_eval

    fn csp_allows_eval(policy : CspPolicy) -> Bool

    Check whether dynamic code evaluation is allowed.

    csp_allows_inline_script

    fn csp_allows_inline_script(policy : CspPolicy) -> Bool

    Check whether inline scripts are allowed.

    csp_core_directives

    fn csp_core_directives() -> Array[String]

    Return the core CSP directives expected for public web applications.

    csp_directive

    fn csp_directive(policy : CspPolicy, name : String) -> CspDirective?

    Return a CSP directive by name.

    csp_effective_values

    fn csp_effective_values(policy : CspPolicy, name : String) -> Array[String]

    Return values for a CSP directive, falling back where CSP semantics expect it.

    csp_fallback_chain

    fn csp_fallback_chain(name : String) -> Array[String]

    Return fallback chain used by this package for a source directive.

    csp_has_nonce_or_hash

    fn csp_has_nonce_or_hash(policy : CspPolicy, directive : String) -> Bool

    Check whether a directive has a nonce or hash source.

    csp_has_source

    fn csp_has_source(policy : CspPolicy, directive : String, source : String) -> Bool

    Check whether a CSP directive contains a source expression.

    csp_source_directive_names

    fn csp_source_directive_names() -> Array[String]

    Return the CSP source directives handled by the simplified CSP auditor.

    csp_source_expression

    fn csp_source_expression(value : String) -> SourceExpression

    Interpret one CSP source expression.

    csp_sources

    fn csp_sources(policy : CspPolicy, directive : String) -> Array[SourceExpression]

    Interpret every source expression in a directive.

    default_baseline

    fn default_baseline(document_origin : String) -> Baseline

    Recommended baseline for public web applications.

    default_security_recommendations

    fn default_security_recommendations() -> Array[HeaderRecommendation]

    Return a stable list of default secure header recommendations.

    deny

    fn deny(feature : String) -> PolicyIntent

    Create an intent that disables a feature.

    device_lab_profile

    fn device_lab_profile() -> BaselineProfile

    Profile for hardware labs that delegate device features to trusted origins.

    device_lab_security_bundle

    fn device_lab_security_bundle(document_origin : String, trusted_device_origins : Array[String]) -> SecurityHeaderBundle

    Hardware lab bundle for WebUSB, WebHID, Bluetooth, and serial demos.

    diff

    fn diff(before : Policy, after : Policy) -> Array[PolicyDiff]

    Compare two policies feature by feature.

    directive

    fn directive(policy : Policy, feature : String) -> Directive?

    Return the first directive for feature, if one is present.

    feature_policy_header

    fn feature_policy_header(headers : HeaderSet) -> String?

    Return combined legacy Feature-Policy header value, if present.

    header_check_severity

    fn header_check_severity(check : HeaderCheck) -> String

    Return the highest severity in a check.

    header_values

    fn header_values(headers : HeaderSet, name : String) -> Array[String]

    known_feature

    fn known_feature(feature : String) -> FeatureSpec?

    Find metadata for one known feature.

    known_feature_names

    fn known_feature_names() -> Array[String]

    Return a normalized list of known feature names.

    known_features

    fn known_features() -> Array[FeatureSpec]

    Return the built-in browser capability catalog.

    matrix_cell

    fn matrix_cell(matrix : AccessMatrix, feature : String, target_origin : String) -> AccessCell?

    Find one cell in an access matrix.

    media_app_profile

    fn media_app_profile() -> BaselineProfile

    Profile for media-heavy sites that need same-origin playback features.

    media_security_bundle

    fn media_security_bundle(document_origin : String, api_origins : Array[String], media_origins : Array[String]) -> SecurityHeaderBundle

    Media app bundle with trusted API and media origins.

    migrate_feature_policy

    fn migrate_feature_policy(header : String) -> String

    Convert legacy Feature-Policy syntax into modern Permissions-Policy.

    minimal_policy_for_contract

    fn minimal_policy_for_contract(contract : CapabilityContract) -> String

    Build the strictest Permissions-Policy header that satisfies a contract.

    minimal_policy_intents

    fn minimal_policy_intents(contract : CapabilityContract) -> Array[PolicyIntent]

    Build policy intents from a capability contract and the known feature catalog.

    named_security_bundle

    fn named_security_bundle(name : String, document_origin : String) -> SecurityHeaderBundle

    Return the strongest bundle among built-in presets for a simple name.

    optional_capability_need

    fn optional_capability_need(feature : String, target_origins : Array[String], reason : String) -> CapabilityNeed

    Declare an optional browser capability for one or more target origins.

    origins_only

    fn origins_only(feature : String, origins : Array[String]) -> PolicyIntent

    Create an intent that allows a feature only for explicit origins.

    parse

    fn parse(header : String) -> Policy

    Parse a modern Permissions-Policy header.

    parse_csp

    fn parse_csp(header : String) -> CspPolicy

    Parse a Content-Security-Policy header.

    parse_feature_policy

    fn parse_feature_policy(header : String) -> Policy

    Parse a legacy Feature-Policy header and normalize it to this package's modern directive representation.

    parse_header_block

    fn parse_header_block(block : String) -> HeaderSet

    Parse the final HTTP response header block, including curl -I -L output.

    permissions_policy_header

    fn permissions_policy_header(headers : HeaderSet) -> String?

    Return combined modern Permissions-Policy header value, if present.

    policy_from_headers

    fn policy_from_headers(headers : HeaderSet) -> Policy

    Choose the effective policy from parsed headers.

    Modern Permissions-Policy takes precedence. Legacy Feature-Policy is used only when no modern header is present.

    profile_baseline

    fn profile_baseline(profile : BaselineProfile, document_origin : String) -> Baseline

    Build an audit baseline that matches a built-in profile.

    profile_header

    fn profile_header(profile : BaselineProfile, trusted_origins : Array[String]) -> String

    Render a complete header for a built-in profile.

    profile_intents

    fn profile_intents(profile : BaselineProfile, trusted_origins : Array[String]) -> Array[PolicyIntent]

    Build declarative intents for a built-in profile.

    profile_name

    fn profile_name(profile : BaselineProfile) -> String

    Return a stable name for a built-in profile.

    profile_policy

    fn profile_policy(profile : BaselineProfile, trusted_origins : Array[String]) -> Policy

    Build a parsed policy for a built-in profile.
    fn recommended_header() -> String

    Render the built-in recommended header.

    render

    fn render(policy : Policy) -> String

    Render a policy back to normalized modern header syntax.

    render_access_matrix

    fn render_access_matrix(matrix : AccessMatrix) -> String

    Render an access matrix as compact line-oriented text.

    render_batch_audit

    fn render_batch_audit(batch : BatchAudit) -> String

    Render a batch audit summary.

    render_batch_gate

    fn render_batch_gate(gate : BatchGate) -> String

    Render a batch gate result.

    render_batch_json

    fn render_batch_json(batch : BatchAudit) -> String

    Render a JSON-like batch report.

    render_batch_markdown

    fn render_batch_markdown(batch : BatchAudit) -> String

    Render a Markdown batch report.

    render_batch_recommendations

    fn render_batch_recommendations(recommendations : Array[BatchRecommendation]) -> String

    Render batch recommendations.

    render_capability_contract_report

    fn render_capability_contract_report(report : CapabilityContractReport) -> String

    Render a contract audit in stable line-oriented text for CI logs.

    render_capability_inventory

    fn render_capability_inventory(audit : CapabilityInventoryAudit) -> String

    Render the inventory and every route result for CI logs.

    render_capability_response_audit

    fn render_capability_response_audit(audit : CapabilityResponseAudit) -> String

    Render a route-level response audit for CI logs.

    render_csp

    fn render_csp(policy : CspPolicy) -> String

    Render CSP back to normalized syntax.

    render_csp_audit

    fn render_csp_audit(report : AuditReport) -> String

    Render a CSP audit report with a CSP-specific heading.

    render_csp_summary

    fn render_csp_summary(summary : CspSummary) -> String

    Render a compact CSP summary.

    render_diffs

    fn render_diffs(diffs : Array[PolicyDiff]) -> String

    Render policy diffs as stable line-oriented text.

    render_header_audit

    fn render_header_audit(audit : HeaderAudit) -> String

    Render an end-to-end header audit result.

    render_header_check

    fn render_header_check(check : HeaderCheck) -> String

    Render one header check.

    render_profile

    fn render_profile(profile : BaselineProfile, trusted_origins : Array[String]) -> String

    Render profile metadata and generated header for documentation or logs.

    render_report

    fn render_report(report : AuditReport) -> String

    Render an audit report as line-oriented text for examples and CI logs.

    render_sample_score

    fn render_sample_score(score : SampleScore) -> String

    Render one sample score.

    render_security_audit

    fn render_security_audit(audit : SecurityAudit) -> String

    Render a full security-header audit as plain text.

    render_security_badge

    fn render_security_badge(audit : SecurityAudit) -> String

    Render a concise one-line audit badge.

    render_security_bundle

    fn render_security_bundle(bundle : SecurityHeaderBundle) -> String

    Render a header bundle as an HTTP response header block.

    render_security_bundle_notes

    fn render_security_bundle_notes(bundle : SecurityHeaderBundle) -> String

    Render bundle notes for documentation.

    render_security_check_table

    fn render_security_check_table(audit : SecurityAudit) -> String

    Render a compact table-like check list for CI logs.

    render_security_coverage

    fn render_security_coverage(coverage : SecurityCoverage) -> String

    Render header coverage as stable text.

    render_security_finding_summary

    fn render_security_finding_summary(summary : SecurityFindingSummary) -> String

    Render finding summary as stable line-oriented text.

    render_security_gate

    fn render_security_gate(gate : SecurityGate) -> String

    Render a CI gate result.

    render_security_json

    fn render_security_json(audit : SecurityAudit) -> String

    Render a deterministic JSON-like text report without external dependencies.

    render_security_markdown

    fn render_security_markdown(audit : SecurityAudit) -> String

    Render a Markdown report for issue comments or release notes.

    render_security_recommendations

    fn render_security_recommendations(recommendations : Array[HeaderRecommendation]) -> String

    Render fix recommendations as line-oriented text.

    render_security_regressions

    fn render_security_regressions(changes : Array[SecurityRegression]) -> String

    Render audit changes as line-oriented text.

    render_security_score

    fn render_security_score(score : SecurityScore) -> String

    Render an audit score.

    render_summary

    fn render_summary(summary : PolicySummary) -> String

    Render a compact summary for CLI output.

    response_sample

    fn response_sample(name : String, path : String, document_origin : String, header_block : String) -> ResponseSample

    Create a response sample.

    response_sample_from_bundle

    fn response_sample_from_bundle(name : String, path : String, bundle : SecurityHeaderBundle) -> ResponseSample

    Create a response sample from a security header bundle.

    security_bundle_names

    fn security_bundle_names() -> Array[String]

    Return all built-in bundle names.

    security_check

    fn security_check(audit : SecurityAudit, header : String) -> HeaderCheck?

    Return a check by header name.

    security_coverage

    fn security_coverage(audit : SecurityAudit) -> SecurityCoverage

    Summarize required header coverage.

    security_finding_codes

    fn security_finding_codes(audit : SecurityAudit) -> Array[String]

    Return unique finding codes across the audit.

    security_findings_by_severity

    fn security_findings_by_severity(audit : SecurityAudit, severity : String) -> Array[Finding]

    Return findings that match a severity label.

    security_gate

    fn security_gate(audit : SecurityAudit, required_grade : String, allow_warnings : Bool) -> SecurityGate

    Build a CI-style gate for a security audit.

    security_grade_at_least

    fn security_grade_at_least(audit : SecurityAudit, grade : String) -> Bool

    Return whether an audit meets a minimum grade.

    security_has_no_high

    fn security_has_no_high(audit : SecurityAudit) -> Bool

    Return whether an audit has no high-severity findings.

    security_header_entry

    fn security_header_entry(name : String, value : String) -> SecurityHeaderEntry

    Create a header entry.

    security_header_names

    fn security_header_names() -> Array[String]

    Return the core response security headers that permscope can audit.

    security_recommendations

    fn security_recommendations(audit : SecurityAudit) -> Array[HeaderRecommendation]

    Return fix recommendations for missing or weak headers.

    self_and_origins

    fn self_and_origins(feature : String, origins : Array[String]) -> PolicyIntent

    Create an intent that allows a feature for self plus explicit origins.

    self_only

    fn self_only(feature : String) -> PolicyIntent

    Create an intent that allows a feature only for the document origin.

    static_site_security_bundle

    fn static_site_security_bundle(document_origin : String) -> SecurityHeaderBundle

    Practical static-site bundle.

    strict_csp_header

    fn strict_csp_header() -> String

    Build a strict starter Content-Security-Policy for static applications.

    strict_profile

    fn strict_profile() -> BaselineProfile

    Profile that disables every known browser capability.

    strict_security_bundle

    fn strict_security_bundle(document_origin : String) -> SecurityHeaderBundle

    Strict browser-facing bundle for high-sensitivity apps.

    summarize

    fn summarize(policy : Policy, baseline : Baseline) -> PolicySummary

    Summarize a policy against a baseline.

    summarize_csp

    fn summarize_csp(policy : CspPolicy) -> CspSummary

    Summarize a CSP policy for dashboards and release notes.

    summarize_security_findings

    fn summarize_security_findings(audit : SecurityAudit) -> SecurityFindingSummary

    Summarize findings across every header check.

    weakest_sample_score

    fn weakest_sample_score(batch : BatchAudit) -> SampleScore?

    Return the weakest sample score in a batch.