@@ -1797,6 +1797,127 @@ describe("registerPolicyDoctorChecks", () => {
17971797 } ) ;
17981798 } ) ;
17991799
1800+ it ( "previews review-required gateway bind repair without mutating config" , async ( ) => {
1801+ const configPath = join ( workspaceDir , "openclaw.jsonc" ) ;
1802+ const cfg = {
1803+ ...cfgWithPolicy ( { workspaceRepairs : true } ) ,
1804+ gateway : { bind : "lan" } ,
1805+ } as unknown as OpenClawConfig ;
1806+ await fs . writeFile ( configPath , "{}" , "utf-8" ) ;
1807+ await fs . writeFile (
1808+ join ( workspaceDir , "policy.jsonc" ) ,
1809+ JSON . stringify ( { gateway : { exposure : { allowNonLoopbackBind : false } } } ) ,
1810+ "utf-8" ,
1811+ ) ;
1812+
1813+ const result = await runPolicyRepairCheck (
1814+ "policy/gateway-non-loopback-bind" ,
1815+ repairCtx ( configPath , cfg ) ,
1816+ ) ;
1817+
1818+ expect ( result . status ) . toBe ( "skipped" ) ;
1819+ expect ( result . reason ) . toBe ( "policy repair requires review before changing config" ) ;
1820+ expect ( result . changes ) . toEqual ( [
1821+ "Review required: set gateway.bind=loopback for policy conformance." ,
1822+ ] ) ;
1823+ expect ( result . warnings ) . toEqual ( [
1824+ "Review required: set gateway.bind=loopback for policy conformance." ,
1825+ ] ) ;
1826+ expect ( result . effects ) . toEqual ( [
1827+ {
1828+ kind : "config" ,
1829+ action : "would-set-after-review" ,
1830+ target : "gateway.bind=loopback" ,
1831+ dryRunSafe : true ,
1832+ } ,
1833+ ] ) ;
1834+ expect ( result . config . gateway ?. bind ) . toBe ( "lan" ) ;
1835+ expect ( result . remainingFindings ) . toHaveLength ( 1 ) ;
1836+ } ) ;
1837+
1838+ it ( "previews review-required custom gateway bind repair without mutating config" , async ( ) => {
1839+ const configPath = join ( workspaceDir , "openclaw.jsonc" ) ;
1840+ const cfg = {
1841+ ...cfgWithPolicy ( { workspaceRepairs : true } ) ,
1842+ gateway : { bind : "custom" , customBindHost : "10.0.0.4" } ,
1843+ } as unknown as OpenClawConfig ;
1844+ await fs . writeFile ( configPath , "{}" , "utf-8" ) ;
1845+ await fs . writeFile (
1846+ join ( workspaceDir , "policy.jsonc" ) ,
1847+ JSON . stringify ( { gateway : { exposure : { allowNonLoopbackBind : false } } } ) ,
1848+ "utf-8" ,
1849+ ) ;
1850+
1851+ const result = await runPolicyRepairCheck (
1852+ "policy/gateway-non-loopback-bind" ,
1853+ repairCtx ( configPath , cfg ) ,
1854+ ) ;
1855+
1856+ expect ( result . findings ) . toEqual ( [
1857+ expect . objectContaining ( {
1858+ ocPath : "oc://openclaw.config/gateway/customBindHost" ,
1859+ } ) ,
1860+ ] ) ;
1861+ expect ( result . status ) . toBe ( "skipped" ) ;
1862+ expect ( result . changes ) . toEqual ( [
1863+ "Review required: set gateway.bind=loopback for policy conformance." ,
1864+ ] ) ;
1865+ expect ( result . warnings ) . toEqual ( [
1866+ "Review required: set gateway.bind=loopback for policy conformance." ,
1867+ ] ) ;
1868+ expect ( result . effects ) . toEqual ( [
1869+ {
1870+ kind : "config" ,
1871+ action : "would-set-after-review" ,
1872+ target : "gateway.bind=loopback" ,
1873+ dryRunSafe : true ,
1874+ } ,
1875+ ] ) ;
1876+ expect ( result . config . gateway ) . toMatchObject ( {
1877+ bind : "custom" ,
1878+ customBindHost : "10.0.0.4" ,
1879+ } ) ;
1880+ expect ( result . remainingFindings ) . toHaveLength ( 1 ) ;
1881+ } ) ;
1882+
1883+ it ( "previews review-required gateway node command repairs without mutating config" , async ( ) => {
1884+ const configPath = join ( workspaceDir , "openclaw.jsonc" ) ;
1885+ const cfg = {
1886+ ...cfgWithPolicy ( { workspaceRepairs : true } ) ,
1887+ gateway : { nodes : { denyCommands : [ "mcp.help" ] } } ,
1888+ } as unknown as OpenClawConfig ;
1889+ await fs . writeFile ( configPath , "{}" , "utf-8" ) ;
1890+ await fs . writeFile (
1891+ join ( workspaceDir , "policy.jsonc" ) ,
1892+ JSON . stringify ( { gateway : { nodes : { denyCommands : [ "mcp.help" , "system.run" ] } } } ) ,
1893+ "utf-8" ,
1894+ ) ;
1895+
1896+ const result = await runPolicyRepairCheck (
1897+ "policy/gateway-node-command-denied" ,
1898+ repairCtx ( configPath , cfg ) ,
1899+ ) ;
1900+
1901+ expect ( result . status ) . toBe ( "skipped" ) ;
1902+ expect ( result . reason ) . toBe ( "policy repair requires review before changing config" ) ;
1903+ expect ( result . changes ) . toEqual ( [
1904+ "Review required: add system.run to gateway.nodes.denyCommands for policy conformance." ,
1905+ ] ) ;
1906+ expect ( result . warnings ) . toEqual ( [
1907+ "Review required: add system.run to gateway.nodes.denyCommands for policy conformance." ,
1908+ ] ) ;
1909+ expect ( result . effects ) . toEqual ( [
1910+ {
1911+ kind : "config" ,
1912+ action : "would-append-after-review" ,
1913+ target : "gateway.nodes.denyCommands += system.run" ,
1914+ dryRunSafe : true ,
1915+ } ,
1916+ ] ) ;
1917+ expect ( result . config . gateway ?. nodes ?. denyCommands ) . toEqual ( [ "mcp.help" ] ) ;
1918+ expect ( result . remainingFindings ) . toHaveLength ( 1 ) ;
1919+ } ) ;
1920+
18001921 it ( "repairs automatic channel ingress narrowing findings" , async ( ) => {
18011922 const configPath = join ( workspaceDir , "openclaw.jsonc" ) ;
18021923 const cfg = {
@@ -2161,7 +2282,7 @@ describe("registerPolicyDoctorChecks", () => {
21612282 ] ) ;
21622283 } ) ;
21632284
2164- it ( "does not register repair for review-required policy findings" , ( ) => {
2285+ it ( "does not register repair for non-previewable policy findings" , ( ) => {
21652286 const check = registerChecks ( ) . find (
21662287 ( entry ) => entry . id === "policy/gateway-http-url-fetch-unrestricted" ,
21672288 ) ;
0 commit comments