11package fs
22
33import (
4+ "context"
45 "os"
56
67 "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
@@ -27,8 +28,9 @@ import (
2728// // when no itemType is provided, it will return both files and directories
2829// const items = fs.ListDir('/tmp');
2930// ```
30- func ListDir (path string , itemType string ) ([]string , error ) {
31- finalPath , err := protocolstate .NormalizePath (path )
31+ func ListDir (ctx context.Context , path string , itemType string ) ([]string , error ) {
32+ executionId := ctx .Value ("executionId" ).(string )
33+ finalPath , err := protocolstate .NormalizePathWithExecutionId (executionId , path )
3234 if err != nil {
3335 return nil , err
3436 }
@@ -57,8 +59,9 @@ func ListDir(path string, itemType string) ([]string, error) {
5759// // here permitted directories are $HOME/nuclei-templates/*
5860// const content = fs.ReadFile('helpers/usernames.txt');
5961// ```
60- func ReadFile (path string ) ([]byte , error ) {
61- finalPath , err := protocolstate .NormalizePath (path )
62+ func ReadFile (ctx context.Context , path string ) ([]byte , error ) {
63+ executionId := ctx .Value ("executionId" ).(string )
64+ finalPath , err := protocolstate .NormalizePathWithExecutionId (executionId , path )
6265 if err != nil {
6366 return nil , err
6467 }
@@ -74,8 +77,8 @@ func ReadFile(path string) ([]byte, error) {
7477// // here permitted directories are $HOME/nuclei-templates/*
7578// const content = fs.ReadFileAsString('helpers/usernames.txt');
7679// ```
77- func ReadFileAsString (path string ) (string , error ) {
78- bin , err := ReadFile (path )
80+ func ReadFileAsString (ctx context. Context , path string ) (string , error ) {
81+ bin , err := ReadFile (ctx , path )
7982 if err != nil {
8083 return "" , err
8184 }
@@ -91,14 +94,14 @@ func ReadFileAsString(path string) (string, error) {
9194// const contents = fs.ReadFilesFromDir('helpers/ssh-keys');
9295// log(contents);
9396// ```
94- func ReadFilesFromDir (dir string ) ([]string , error ) {
95- files , err := ListDir (dir , "file" )
97+ func ReadFilesFromDir (ctx context. Context , dir string ) ([]string , error ) {
98+ files , err := ListDir (ctx , dir , "file" )
9699 if err != nil {
97100 return nil , err
98101 }
99102 var results []string
100103 for _ , file := range files {
101- content , err := ReadFileAsString (dir + "/" + file )
104+ content , err := ReadFileAsString (ctx , dir + "/" + file )
102105 if err != nil {
103106 return nil , err
104107 }
0 commit comments