File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed
agent/hooks/instrumentation Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export function generateBuildinShim(
2323 ( m ) => ! methods . some ( ( method ) => method . name === m . name )
2424 ) ;
2525
26+ // Todos: Copy over properties of patched methods?
2627 return `
2728 const orig = process.getBuiltinModule(${ JSON . stringify ( builtinName ) } );
2829 const { __instrumentInspectArgs } = require('@aikidosec/firewall/instrument/internals');
Original file line number Diff line number Diff line change 11import { getInstance } from "../../AgentSingleton" ;
2- import { getPackageCallbacks } from "./instructions" ;
2+ import { getBuiltinCallbacks , getPackageCallbacks } from "./instructions" ;
33
44export function __instrumentInspectArgs (
55 id : string ,
@@ -12,7 +12,13 @@ export function __instrumentInspectArgs(
1212 }
1313
1414 if ( isBuiltin ) {
15- // Todo
15+ const callbacks = getBuiltinCallbacks ( id ) ;
16+
17+ if ( typeof callbacks . inspectArgs === "function" ) {
18+ // Todo support subject?
19+ callbacks . inspectArgs ( args , agent , undefined ) ;
20+ }
21+
1622 return ;
1723 }
1824
Original file line number Diff line number Diff line change @@ -138,3 +138,9 @@ export function getPackageCallbacks(
138138) : IntereptorFunctionsObj {
139139 return packageFileCallbacks . get ( identifier ) || { } ;
140140}
141+
142+ export function getBuiltinCallbacks (
143+ identifier : string
144+ ) : IntereptorFunctionsObj {
145+ return builtinCallbacks . get ( identifier ) || { } ;
146+ }
Original file line number Diff line number Diff line change @@ -153,8 +153,19 @@ export class FileSystem implements Wrapper {
153153 this . wrapPromises ( exports . promises , pkgInfo ) ;
154154 } ) ;
155155
156- hooks
157- . addBuiltinModule ( "fs/promises" )
158- . onRequire ( ( exports , pkgInfo ) => this . wrapPromises ( exports , pkgInfo ) ) ;
156+ const fsPromises = hooks . addBuiltinModule ( "fs/promises" ) ;
157+ fsPromises . onRequire ( ( exports , pkgInfo ) =>
158+ this . wrapPromises ( exports , pkgInfo )
159+ ) ;
160+ fsPromises . setInstrumentationInstruction ( {
161+ functions : [
162+ {
163+ name : "readFile" ,
164+ inspectArgs : ( args ) => {
165+ console . log ( "readFile" , args ) ;
166+ } ,
167+ } ,
168+ ] ,
169+ } ) ;
159170 }
160171}
You can’t perform that action at this time.
0 commit comments