@@ -49,6 +49,13 @@ function git(cwd: string, ...args: string[]) {
4949 return execFileSync ( "git" , args , { cwd, encoding : "utf8" } ) . trim ( ) ;
5050}
5151
52+ function setTrustedGitConfig ( cwd : string , key : string , value : string ) {
53+ git ( cwd , "config" , key , value ) ;
54+ // Git replaces config through a lockfile, inheriting the runner umask. Keep
55+ // this trusted fixture deterministic without weakening the production guard.
56+ chmodSync ( path . join ( cwd , ".git/config" ) , 0o600 ) ;
57+ }
58+
5259function fetchFixtureMain ( checkout : string , remote : string ) {
5360 const origin = fixtureOrigins . get ( checkout ) ;
5461 if ( ! origin ) {
@@ -115,7 +122,11 @@ function writeBuild(mirror: string) {
115122 mkdirSync ( path . join ( mirror , "dist/control-ui" ) , { recursive : true } ) ;
116123 const head = git ( mirror , "rev-parse" , "HEAD" ) ;
117124 writeFileSync ( path . join ( mirror , "dist/build-info.json" ) , `${ JSON . stringify ( { commit : head } ) } \n` ) ;
118- writeFileSync ( path . join ( mirror , "dist/index.js" ) , "// built\n" ) ;
125+ const gatewayEntrypoint = path . join ( mirror , "dist/index.js" ) ;
126+ writeFileSync ( gatewayEntrypoint , "// built\n" ) ;
127+ // Snapshot ownership rejects group-writable executables, so fixtures must
128+ // not inherit a permissive CI umask and accidentally model an unsafe build.
129+ chmodSync ( gatewayEntrypoint , 0o600 ) ;
119130 writeFileSync ( path . join ( mirror , "dist/entry.js" ) , "// built\n" ) ;
120131 mkdirSync ( path . join ( mirror , "dist/control-ui/assets" ) , { recursive : true } ) ;
121132 writeFileSync (
@@ -589,24 +600,29 @@ describe("openclaw live updater", () => {
589600 expect ( isOwnedGatewayEntrypoint ( mirror , home , entrypoint ) ) . toBe ( true ) ;
590601 expect ( isOwnedGatewayEntrypoint ( mirror , home , path . join ( mirror , "dist/index.js" ) ) ) . toBe ( true ) ;
591602
603+ chmodSync ( entrypoint , 0o620 ) ;
604+ expect ( isOwnedGatewayEntrypoint ( mirror , home , entrypoint ) ) . toBe ( false ) ;
605+ chmodSync ( entrypoint , 0o600 ) ;
606+
592607 const fsmonitorMarker = path . join ( root , "fsmonitor-ran" ) ;
593608 const fsmonitorHook = path . join ( root , "fsmonitor.sh" ) ;
594609 writeFileSync ( fsmonitorHook , `#!/bin/sh\ntouch ${ fsmonitorMarker } \n` ) ;
595610 chmodSync ( fsmonitorHook , 0o755 ) ;
596- git ( snapshot , "config" , "core.fsmonitor" , fsmonitorHook ) ;
611+ setTrustedGitConfig ( snapshot , "core.fsmonitor" , fsmonitorHook ) ;
597612 rmSync ( fsmonitorMarker , { force : true } ) ;
598613 expect ( isOwnedGatewayEntrypoint ( mirror , home , entrypoint ) ) . toBe ( true ) ;
599614 expect ( existsSync ( fsmonitorMarker ) ) . toBe ( false ) ;
600615
601616 git ( snapshot , "switch" , "-c" , "mutable" ) ;
602617 expect ( isOwnedGatewayEntrypoint ( mirror , home , entrypoint ) ) . toBe ( false ) ;
603618 git ( snapshot , "checkout" , "--detach" , head ) ;
619+ chmodSync ( path . join ( snapshot , ".git/HEAD" ) , 0o600 ) ;
604620
605621 const filterMarker = path . join ( root , "filter-ran" ) ;
606622 const filterHook = path . join ( root , "filter.sh" ) ;
607623 writeFileSync ( filterHook , `#!/bin/sh\ntouch ${ filterMarker } \ncat\n` ) ;
608624 chmodSync ( filterHook , 0o755 ) ;
609- git ( snapshot , "config" , "filter.untrusted.clean" , filterHook ) ;
625+ setTrustedGitConfig ( snapshot , "filter.untrusted.clean" , filterHook ) ;
610626 mkdirSync ( path . join ( snapshot , ".git/info" ) , { recursive : true } ) ;
611627 writeFileSync ( path . join ( snapshot , ".git/info/attributes" ) , "README.md filter=untrusted\n" ) ;
612628 writeFileSync ( path . join ( snapshot , "README.md" ) , "dirty\n" ) ;
0 commit comments