PageSourceSearch

https://agenttrust.ai/assets/OpenClawGuardrailsPage-BIMt2MCu.js

js agenttrust.ai collected 2026-10-05 11:47:23 UTC 19,965 bytes, 3 lines download raw bytes

1import{a as se,n as ae,r as i,j as e,D as I,x as re,e as U,d as C,w as le,o as ne,y as oe,H as ie,g as de,q as ce,c as ue,B as xe,C as me}from"./index-D9WyEDzj.js";const $=["exec","message","browser","write","nodes"],q=250,ge=1e3,he={exec:[{id:"block-destructive-command",enabled:!0,fieldPath:"command",operator:"regex",value:"(?:^|\\s)(?:rm\\s+-rf\\b|dd\\s+if=\\b|mkfs\\b|curl\\b[^\\n]*\\|\\s*(?:bash|sh)\\b|wget\\b[^\\n]*\\|\\s*(?:bash|sh)\\b)",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"critical",reason:"Dangerous command pattern detected.",caseSensitive:!1,validationMethods:["pattern"]},{id:"flag-privilege-escalation",enabled:!0,fieldPath:"command",operator:"regex",value:"\\b(?:sudo|su|pkexec)\\b",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"high",reason:"Privilege escalation command detected.",caseSensitive:!1,validationMethods:["pattern"]}],message:[{id:"block-sensitive-credentials",enabled:!0,fieldPath:"content",operator:"regex",value:"(?:api[_-]?key|secret|password|token|private[_-]?key)",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"high",reason:"Potential sensitive credential disclosure in message.",caseSensitive:!1,validationMethods:["pattern"]}],browser:[{id:"url-allowlist",enabled:!1,fieldPath:"url",operator:"allowlist",value:"",values:[],allowlistMatchType:"contains",action:"block",riskLevel:"medium",reason:"URL is not in allowed browser destinations.",caseSensitive:!1,validationMethods:["allowlist"]}],write:[{id:"block-system-paths",enabled:!0,fieldPath:"path",operator:"regex",value:"^(?:/etc\\b|/sys\\b|/proc\\b|/root\\b|C:\\\\Windows\\\\System32\\\\)",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"high",reason:"Write attempt to restricted system path.",caseSensitive:!1,validationMethods:["pattern"]}],nodes:[{id:"node-action-allowlist",enabled:!1,fieldPath:"action",operator:"allowlist",value:"",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"medium",reason:"Node action is not in allowed actions.",caseSensitive:!1,validationMethods:["allowlist"]}]};function b(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function S(t){return typeof t!="string"?"":t.trim().toLowerCase().replace(/[^a-z0-9_.-]/g,"").slice(0,80)}function M(t,o="continue"){return t==="continue"||t==="block"?t:o}function pe(t,o="continue"){return t==="continue"||t==="block"?t:o}function be(t,o="medium"){return t==="low"||t==="medium"||t==="high"||t==="critical"?t:o}function fe(t,o="regex"){return t==="regex"||t==="contains"||t==="matches"||t==="allowlist"?t:o}function ye(t,o="matches"){return t==="contains"||t==="matches"||t==="regex"?t:o}function T(t){return Array.isArray(t)?Array.from(new Set(t.map(o=>typeof o=="string"?o.trim():"").filter(o=>o.length>0&&o.length<=300))):[]}function ve(t){return{...t,values:[...t.values],validationMethods:[...t.validationMethods]}}function A(t){return{enabled:!1,await:!0,fallbackOnError:"continue",defaultAction:"continue",rules:(he[t]||[]).map(d=>ve(d))}}function je(t,o){return b(t)?{id:typeof t.id=="string"&&t.id.trim().length>0?t.id.trim().slice(0,120):o,enabled:typeof t.enabled=="boolean"?t.enabled:!0,fieldPath:typeof t.fieldPath=="string"&&t.fieldPath.trim().length>0?t.fieldPath.trim().slice(0,120):"parameters",operator:fe(t.operator,"regex"),value:typeof t.value=="string"?t.value.slice(0,500):"",values:T(t.values),allowlistMatchType:ye(t.allowlistMatchType,"matches"),action:M(t.action,"block"),riskLevel:be(t.riskLevel,"medium"),reason:typeof t.reason=="string"&&t.reason.trim().length>0?t.reason.trim().slice(0,300):"Guardrail rule matched.",caseSensitive:typeof t.caseSensitive=="boolean"?t.caseSensitive:!1,validationMethods:T(t.validationMethods).length>0?T(t.validationMethods).slice(0,8):["pattern"]}:{id:o,enabled:!0,fieldPath:"parameters",operator:"regex",value:"",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"medium",reason:"Guardrail rule matched.",caseSensitive:!1,validationMethods:["pattern"]}}function we(t,o){const d=A(o);return b(t)?{enabled:typeof t.enabled=="boolean"?t.enabled:d.enabled,await:typeof t.await=="boolean"?t.await:d.await,fallbackOnError:pe(t.fallbackOnError,d.fallbackOnError),defaultAction:M(t.defaultAction,d.defaultAction),rules:Array.isArray(t.rules)?t.rules.map((f,y)=>je(f,`rule_${y+1}`)):d.rules}:d}function Ne(){return`rule_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function Ce(){const{user:t}=se();ae();const[o,d]=i.useState(!0),[f,y]=i.useState(!1),[_,m]=i.useState(null),[v,O]=i.useState(!0),[j,L]=i.useState("continue"),[g,w]=i.useState({}),[E,P]=i.useState([]),[R,D]=i.useState(""),N=!0;i.useEffect(()=>{document.title="OpenClaw Guardrails | AgentTrust"},[]);const G=async()=>{d(!0),m(null);try{if(!t?.id){w({}),P([]);return}const s=await re(U(C,"openclaw_guardrails_settings",t.id)),n=new Set;let a=0,r=null;for(;a<ge;){const x=[le("owner_uid","==",t.id),ne("received_at","desc"),oe(q)];r&&x.push(ie(r));const h=await de(ce(ue(C,"openclaw_cloud_logs"),...x));if(h.empty)break;for(const ee of h.docs){const te=ee.data(),B=S(te.tool_name);B&&n.add(B)}if(n.size>=25||(a+=h.docs.length,r=h.docs[h.docs.length-1],h.docs.length<q))break}const l=s.exists()?s.data():null,u=b(l?.toolGate)?l.toolGate:null,K=typeof u?.enabled=="boolean"?u.enabled:typeof l?.tool_gate_enabled=="boolean"?l.tool_gate_enabled:!0,Q=M(u?.defaultAction??l?.default_action,"continue"),k=b(u?.tools)?u.tools:b(l?.tools)?l.tools:{},Y=new Set([...$,...n,...Object.keys(k).map(x=>
1S(x)).filter(Boolean)]),z={};for(const x of Y)z[x]=we(b(k)?k[x]:void 0,x);O(K),L(Q),w(z),P(Array.from(n).sort((x,h)=>x.localeCompare(h)))}catch(s){console.error("Failed to load OpenClaw guardrails:",s),m(s.message||"Failed to load guardrails.")}finally{d(!1)}};i.useEffect(()=>{G().catch(s=>{console.error("Unexpected guardrails load error:",s),m(s.message||"Failed to load guardrails."),d(!1)})},[t?.id,N]);const H=i.useMemo(()=>{const s=Object.keys(g),n=new Map($.map((a,r)=>[a,r]));return s.sort((a,r)=>{const l=n.has(a),u=n.has(r);return l&&u?(n.get(a)??0)-(n.get(r)??0):l?-1:u?1:a.localeCompare(r)})},[g]),F=i.useMemo(()=>Object.values(g).filter(s=>s.enabled).length,[g]),J=i.useMemo(()=>{const s={};for(const[n,a]of Object.entries(g))a.enabled&&(s[n]={fallbackOnError:a.fallbackOnError});return{version:"1.0",updatedAt:new Date().toISOString(),guardrails:{toolGate:{enabled:v,defaultAction:j,tools:s}}}},[g,v,j]),p=(s,n)=>{w(a=>{const r=a[s]||A(s);return{...a,[s]:n(r)}})},W=s=>{p(s,n=>({...n,rules:[...n.rules,{id:Ne(),enabled:!0,fieldPath:"parameters",operator:"regex",value:"",values:[],allowlistMatchType:"matches",action:"block",riskLevel:"medium",reason:"Guardrail rule matched.",caseSensitive:!1,validationMethods:["pattern"]}]}))},V=(s,n)=>{p(s,a=>({...a,rules:a.rules.filter(r=>r.id!==n)}))},c=(s,n,a)=>{p(s,r=>({...r,rules:r.rules.map(l=>l.id===n?a(l):l)}))},X=()=>{const s=S(R);if(!s){m("Tool name must contain letters/numbers only.");return}w(n=>({...n,[s]:n[s]||A(s)})),D(""),m(null)},Z=async()=>{if(t?.id){y(!0),m(null);try{await xe(U(C,"openclaw_guardrails_settings",t.id),{owner_uid:t.id,version:"1.0",tool_gate_enabled:v,default_action:j,tools:g,updated_at:me(),updated_by:t.email||t.id},{merge:!0}),m("Guardrails saved.")}catch(s){console.error("Failed to save OpenClaw guardrails:",s),m(s.message||"Failed to save guardrails.")}finally{y(!1)}}};return o?e.jsx(I,{children:e.jsx("div",{className:"px-4 py-6 sm:px-0",children:e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-12 text-center",children:[e.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),e.jsx("p",{className:"mt-4 text-sm text-gray-600",children:"Loading guardrails..."})]})})}):e.jsx(I,{children:e.jsxs("div",{className:"px-4 py-6 sm:px-0 relative",children:[e.jsxs("div",{className:"",children:[e.jsx("div",{className:"flex flex-wrap items-start justify-between gap-4 mb-6",children:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-bold text-gray-900",children:[e.jsx("span",{className:"mr-2",role:"img","aria-label":"Lobster",children:"🦞"}),"OpenClaw Guardrails"]}),e.jsxs("div",{className:"text-sm text-gray-600 mt-1 space-y-1",children:[e.jsx("p",{children:"Define your custom guardrails:"}),e.jsx("p",{children:"1. Restrict tool functionalities"}),e.jsx("p",{children:"2. Set custom rules and execution policies"}),e.jsx("p",{children:"3. Apply bespoke behaviours/policies"}),e.jsx("p",{children:"Then publish."})]})]})}),_&&e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6",children:e.jsx("p",{className:"text-sm text-blue-700",children:_})}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-5 mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 mb-4",children:"Global Tool Gate"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex items-center justify-between border border-gray-200 rounded-lg px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Enable Tool Gate"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Master switch for all tool guardrails."})]}),e.jsx("input",{type:"checkbox",checked:v,onChange:s=>O(s.target.checked),className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"})]}),e.jsxs("label",{className:"border border-gray-200 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 mb-2",children:"Default action (tool not configured)"}),e.jsxs("select",{value:j,onChange:s=>L(s.target.value),className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm bg-white",children:[e.jsx("option",{value:"continue",children:"continue"}),e.jsx("option",{value:"block",children:"block"})]})]})]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-3",children:[F," tool",F===1?"":"s"," currently included in manifest."]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-5 mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 mb-2",children:"Tool Inventory"}),e.jsx("p",{className:"text-xs text-gray-600 mb-4",children:"Core tools are always listed. Additional tools are discovered from your Cloud Logs history."}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:"Regex rules can reuse patterns from your Pattern Library for consistent detection across tools."}),E.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-gray-500 mb-2",children:"Discovered from logs"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:E.map(s=>e.jsx("span",{className:"inline-flex items-center rounded-full bg-indigo-50 border border-indigo-200 px-2.5 py-1 text-xs font-medium text-indigo-700",children:s},s))})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:R,onChange:s=>D(s.target.value),placeholder:"Add custom tool name...",className:"min-w-[240px] rounded-md border border-gray-300 px-3 py-2 text-sm"}),e.jsx("button",{type:"button",onClick:X,className:"inline-flex items-center px-3 py-2 rounded-md text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700",children:"Add Tool"})]})]}),e.jsx("div",{className:"space-y-4 mb-6",children:H.map(s=>{const n=g[s];return e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold text-gray-900",children:s}),e.jsx("p",{className:"text-xs text-gray-500",children:"Enable to include this tool in the published guardrail manifest."})]}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium border ${n.enabled?"bg-emerald-50 text-emerald-700 border-emerald-200":"bg-gray-100 text-gray-700 border-gray-200"}`,children:n.enabled?"In manifest":"Disabled"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-3 mb-4",children:[e.jsxs("label",{className:"flex items-center justify-between border border-gray-200 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"text-sm text-gray-800",children:"Apply guardrail"}),e.jsx("input",{type:"checkbox",checked:n.enabled,onChange:a=>p(s,r=>({...r,enabled:a.target.checked}
1)),className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"})]}),e.jsxs("label",{className:"flex items-center justify-between border border-gray-200 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"text-sm text-gray-800",children:"Await validation"}),e.jsx("input",{type:"checkbox",checked:n.await,onChange:a=>p(s,r=>({...r,await:a.target.checked})),className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"})]}),e.jsxs("label",{className:"border border-gray-200 rounded-lg px-3 py-2",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Fallback on error"}),e.jsxs("select",{value:n.fallbackOnError,onChange:a=>p(s,r=>({...r,fallbackOnError:a.target.value})),className:"w-full rounded-md border border-gray-300 px-2 py-1.5 text-sm bg-white",children:[e.jsx("option",{value:"continue",children:"continue"}),e.jsx("option",{value:"block",children:"block"})]})]}),e.jsxs("label",{className:"border border-gray-200 rounded-lg px-3 py-2",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Default action (no rule)"}),e.jsxs("select",{value:n.defaultAction,onChange:a=>p(s,r=>({...r,defaultAction:a.target.value})),className:"w-full rounded-md border border-gray-300 px-2 py-1.5 text-sm bg-white",children:[e.jsx("option",{value:"continue",children:"continue"}),e.jsx("option",{value:"block",children:"block"})]})]})]}),e.jsxs("div",{className:"border border-gray-200 rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Rules"}),e.jsx("button",{type:"button",onClick:()=>W(s),className:"inline-flex items-center px-3 py-1.5 rounded-md text-xs font-medium text-white bg-indigo-600 hover:bg-indigo-700",children:"Add Rule"})]}),n.rules.length===0?e.jsx("p",{className:"px-4 py-4 text-sm text-gray-500",children:"No rules configured for this tool."}):e.jsx("div",{className:"divide-y divide-gray-200",children:n.rules.map(a=>e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-gray-500",children:a.id}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"inline-flex items-center gap-2 text-xs text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:r=>c(s,a.id,l=>({...l,enabled:r.target.checked})),className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"}),"enabled"]}),e.jsx("button",{type:"button",onClick:()=>V(s,a.id),className:"text-xs font-medium text-red-600 hover:text-red-700",children:"Remove"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-3",children:[e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Field path"}),e.jsx("input",{value:a.fieldPath,onChange:r=>c(s,a.id,l=>({...l,fieldPath:r.target.value})),placeholder:"command, workdir, url, content...",className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm"})]}),e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Operator"}),e.jsxs("select",{value:a.operator,onChange:r=>c(s,a.id,l=>({...l,operator:r.target.value})),className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm bg-white",children:[e.jsx("option",{value:"regex",children:"regex"}),e.jsx("option",{value:"contains",children:"contains"}),e.jsx("option",{value:"matches",children:"matches"}),e.jsx("option",{value:"allowlist",children:"allowlist"})]})]}),e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Action"}),e.jsxs("select",{value:a.action,onChange:r=>c(s,a.id,l=>({...l,action:r.target.value})),className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm bg-white",children:[e.jsx("option",{value:"block",children:"block"}),e.jsx("option",{value:"continue",children:"continue"})]})]}),e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Risk level"}),e.jsxs("select",{value:a.riskLevel,onChange:r=>c(s,a.id,l=>({...l,riskLevel:r.target.value})),className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm bg-white",children:[e.jsx("option",{value:"low",children:"low"}),e.jsx("option",{value:"medium",children:"medium"}),e.jsx("option",{value:"high",children:"high"}),e.jsx("option",{value:"critical",children:"critical"})]})]})]}),a.operator==="allowlist"?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Allowlist entr
1ies (one per line)"}),e.jsx("textarea",{value:a.values.join(`
2`),onChange:r=>c(s,a.id,l=>({...l,values:r.target.value.split(`
3`).map(u=>u.trim()).filter(Boolean)})),className:"w-full min-h-[100px] rounded-md border border-gray-300 px-3 py-2 text-sm font-mono"})]}),e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Allowlist match type"}),e.jsxs("select",{value:a.allowlistMatchType,onChange:r=>c(s,a.id,l=>({...l,allowlistMatchType:r.target.value})),className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm bg-white",children:[e.jsx("option",{value:"matches",children:"matches"}),e.jsx("option",{value:"contains",children:"contains"}),e.jsx("option",{value:"regex",children:"regex"})]})]})]}):e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Pattern / value"}),e.jsx("input",{value:a.value,onChange:r=>c(s,a.id,l=>({...l,value:r.target.value})),placeholder:a.operator==="regex"?"e.g. rm\\s+-rf":"Value to match",className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm font-mono"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("label",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Reason"}),e.jsx("input",{value:a.reason,onChange:r=>c(s,a.id,l=>({...l,reason:r.target.value})),className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm"})]}),e.jsxs("label",{className:"flex items-center justify-between border border-gray-200 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"text-sm text-gray-800",children:"Case sensitive"}),e.jsx("input",{type:"checkbox",checked:a.caseSensitive,onChange:r=>c(s,a.id,l=>({...l,caseSensitive:r.target.checked})),className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"})]})]})]},a.id))})]})]},s)})}),e.jsx("div",{className:"bg-white border border-gray-200 rounded-lg p-5 mb-6",children:e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-gray-900",children:"Preview manifest JSON"}),e.jsx("pre",{className:"mt-3 rounded-md border border-gray-200 bg-gray-50 p-3 text-xs text-gray-800 overflow-auto",children:JSON.stringify(J,null,2)})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Z,disabled:f,className:"inline-flex items-center px-4 py-2 rounded-md text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 disabled:bg-gray-400",children:f?"Saving...":"Save Guardrails"}),e.jsx("button",{type:"button",onClick:()=>{G().catch(()=>{})},className:"inline-flex items-center px-4 py-2 rounded-md text-sm font-medium text-gray-700 border border-gray-300 bg-white hover:bg-gray-50",children:"Reload"})]})]}),!N]})})}export{Ce as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.