@@ -4,11 +4,10 @@ package main
4
4
//go:generate depstubber -vendor github.com/beego/beego/v2/server/web/context BeegoOutput,Context
5
5
//go:generate depstubber -vendor github.com/gin-gonic/gin Context Default
6
6
//go:generate depstubber -vendor github.com/gofiber/fiber/v2 Ctx New
7
- //go:generate depstubber -vendor github.com/kataras/iris/v12 Context
7
+ //go:generate depstubber -vendor github.com/kataras/iris/v12/context Context
8
8
//go:generate depstubber -vendor github.com/labstack/echo/v4 Context New
9
9
//go:generate depstubber -vendor github.com/spf13/afero Afero,RegexpFs,HttpFs,ReadOnlyFs,MemMapFs,OsFs,BasePathFs WriteReader,SafeWriteReader,WriteFile,ReadFile,ReadDir,NewOsFs,NewRegexpFs,NewReadOnlyFs,NewCacheOnReadFs,,NewHttpFs,NewBasePathFs,NewIOFS
10
10
11
-
12
11
import (
13
12
"fmt"
14
13
beego "github.com/beego/beego/v2/server/web"
@@ -29,68 +28,67 @@ func main() {
29
28
30
29
func BeegoController (beegoController beego.Controller ) {
31
30
beegoOutput := BeegoContext.BeegoOutput {}
32
- beegoOutput .Download ("filepath" , "license.txt" )
31
+ beegoOutput .Download ("filepath" , "license.txt" ) // $ FileSystemAccess="filepath"
33
32
buffer := make ([]byte , 10 )
34
- _ = beegoController .SaveToFileWithBuffer ("filenameExistsInForm" , "filepath" , buffer )
33
+ _ = beegoController .SaveToFileWithBuffer ("filenameExistsInForm" , "filepath" , buffer ) // $ FileSystemAccess="filepath"
35
34
}
36
35
37
36
func Afero (writer http.ResponseWriter , request * http.Request ) {
38
37
filepath := request .URL .Query ()["filepath" ][0 ]
39
38
//osFS := afero.NewMemMapFs()
40
39
// OR
41
40
osFS := afero .NewOsFs ()
42
- fmt .Println (osFS .MkdirAll ("tmp/b" , 0755 ))
43
- fmt .Println (afero .WriteFile (osFS , "tmp/a" , []byte ("this is me a !" ), 0755 ))
44
- fmt .Println (afero .WriteFile (osFS , "tmp/b/c" , []byte ("this is me c !" ), 0755 ))
45
- fmt .Println (afero .WriteFile (osFS , "tmp/d" , []byte ("this is me d !" ), 0755 ))
46
- content , _ := afero .ReadFile (osFS , filepath )
41
+ fmt .Println (osFS .MkdirAll (filepath , 0755 )) // $ FileSystemAccess=filepath
42
+ fmt .Println (afero .WriteFile (osFS , filepath , []byte ("this is me a !" ), 0755 )) // $ FileSystemAccess=filepath
43
+ content , _ := afero .ReadFile (osFS , filepath ) // $ FileSystemAccess=filepath
47
44
fmt .Println (string (content ))
48
- fmt .Println (osFS .Open (filepath ))
49
- // BAD
50
- fmt .Println (afero .SafeWriteReader (osFS , filepath , os .Stdout ))
51
- fmt .Println (afero .WriteReader (osFS , filepath , os .Stdout ))
45
+ fmt .Println (osFS .Open (filepath )) // $ FileSystemAccess=filepath
46
+ // NOT OK
47
+ fmt .Println (afero .SafeWriteReader (osFS , filepath , os .Stdout )) // $ FileSystemAccess=filepath
48
+ fmt .Println (afero .WriteReader (osFS , filepath , os .Stdout )) // $ FileSystemAccess=filepath
52
49
53
- // RegexpFs ==> BAD
50
+ // RegexpFs ==> NOT OK
54
51
fmt .Println ("RegexpFs:" )
55
52
regex , _ := regexp .Compile (".*" )
56
53
regexpFs := afero .NewRegexpFs (osFS , regex )
57
- fmt .Println (afero .ReadFile (regexpFs , filepath ))
54
+ fmt .Println (afero .ReadFile (regexpFs , filepath )) // $ FileSystemAccess=filepath
58
55
59
- // ReadOnlyFS ==> BAD
56
+ // ReadOnlyFS ==> NOT OK
60
57
fmt .Println ("ReadOnlyFS:" )
61
58
readOnlyFS := afero .NewReadOnlyFs (osFS )
62
- fmt .Println (afero .ReadFile (readOnlyFS , filepath ))
59
+ fmt .Println (afero .ReadFile (readOnlyFS , filepath )) // $ FileSystemAccess=filepath
63
60
64
- // CacheOnReadFs ==> BAD
61
+ // CacheOnReadFs ==> NOT OK
65
62
fmt .Println ("CacheOnReadFs:" )
66
63
cacheOnReadFs := afero .NewCacheOnReadFs (osFS , osFS , 10 )
67
- fmt .Println (afero .ReadFile (cacheOnReadFs , filepath ))
64
+ fmt .Println (afero .ReadFile (cacheOnReadFs , filepath )) // $ FileSystemAccess=filepath
68
65
69
- // HttpFS ==> BAD
66
+ // HttpFS ==> NOT OK
70
67
fmt .Println ("HttpFS:" )
71
68
httpFs := afero .NewHttpFs (osFS )
72
- httpFile , _ := httpFs .Open (filepath )
69
+ httpFile , _ := httpFs .Open (filepath ) // $ FileSystemAccess=filepath
73
70
tmpbytes := make ([]byte , 30 )
74
71
fmt .Println (httpFile .Read (tmpbytes ))
75
72
fmt .Println (string (tmpbytes ))
76
73
77
- // osFS ==> BAD
74
+ // osFS ==> NOT OK
78
75
fmt .Println ("Afero:" )
79
- afs := & afero.Afero {Fs : osFS }
80
- fmt .Println (afs .ReadFile (filepath ))
76
+ afs := & afero.Afero {Fs : osFS } // $ succ=&... pred=osFS
77
+ fmt .Println (afs .ReadFile (filepath )) // $ FileSystemAccess=filepath
81
78
82
- // BasePathFs ==> BAD
79
+ // BasePathFs ==> OK
83
80
fmt .Println ("Afero:" )
84
- basePathFs0 := & afero.Afero {Fs : afero .NewBasePathFs (osFS , "tmp" )}
85
- fmt .Println (basePathFs0 .ReadFile (filepath ))
81
+ newBasePathFs := afero .NewBasePathFs (osFS , "tmp" )
82
+ basePathFs0 := & afero.Afero {Fs : newBasePathFs } // $ succ=&... pred=newBasePathFs
83
+ fmt .Println (basePathFs0 .ReadFile (filepath )) // $ SPURIOUS: FileSystemAccess=filepath
86
84
87
- // IOFS ==> GOOD
85
+ // IOFS ==> OK
88
86
fmt .Println ("IOFS:" )
89
87
ioFS := afero .NewIOFS (osFS )
90
88
fmt .Println (ioFS .ReadFile (filepath ))
91
89
fmt .Println (ioFS .Open (filepath ))
92
90
93
- // BasePathFs ==> GOOD
91
+ // BasePathFs ==> OK
94
92
fmt .Println ("BasePathFs:" )
95
93
basePathFs := afero .NewBasePathFs (osFS , "tmp" )
96
94
fmt .Println (afero .ReadFile (basePathFs , filepath ))
@@ -100,11 +98,13 @@ func Afero(writer http.ResponseWriter, request *http.Request) {
100
98
func Echo () {
101
99
e := echo .New ()
102
100
e .GET ("/" , func (c echo.Context ) error {
103
- return c .File (c .QueryParam ("filePath" ))
101
+ filepath := c .QueryParam ("filePath" )
102
+ return c .File (filepath ) // $ FileSystemAccess=filepath
104
103
})
105
104
106
105
e .GET ("/attachment" , func (c echo.Context ) error {
107
- return c .Attachment (c .QueryParam ("filePath" ), "file name in response" )
106
+ filepath := c .QueryParam ("filePath" )
107
+ return c .Attachment (filepath , "file name in response" ) // $ FileSystemAccess=filepath
108
108
})
109
109
_ = e .Start (":1323" )
110
110
}
@@ -114,32 +114,32 @@ func Fiber() {
114
114
app .Get ("/b" , func (c * fiber.Ctx ) error {
115
115
filepath := c .Params ("filepath" )
116
116
header , _ := c .FormFile ("f" )
117
- _ = c .SaveFile (header , filepath )
118
- return c .SendFile (filepath )
117
+ _ = c .SaveFile (header , filepath ) // $ FileSystemAccess=filepath
118
+ return c .SendFile (filepath ) // $ FileSystemAccess=filepath
119
119
})
120
120
_ = app .Listen (":3000" )
121
121
}
122
122
123
123
func IrisTest (ctx context.Context ) {
124
124
filepath := ctx .URLParam ("filepath" )
125
- _ = ctx .SendFile (filepath , "file" )
126
- _ = ctx .SendFileWithRate (filepath , "file" , 0 , 0 )
127
- _ = ctx .ServeFile (filepath )
128
- _ = ctx .ServeFileWithRate (filepath , 0 , 0 )
129
- _ , _ , _ = ctx .UploadFormFiles (filepath , nil )
125
+ _ = ctx .SendFile (filepath , "file" ) // $ FileSystemAccess=filepath
126
+ _ = ctx .SendFileWithRate (filepath , "file" , 0 , 0 ) // $ FileSystemAccess=filepath
127
+ _ = ctx .ServeFile (filepath ) // $ FileSystemAccess=filepath
128
+ _ = ctx .ServeFileWithRate (filepath , 0 , 0 ) // $ FileSystemAccess=filepath
129
+ _ , _ , _ = ctx .UploadFormFiles (filepath , nil ) // $ FileSystemAccess=filepath
130
130
_ , fileHeader , _ := ctx .FormFile ("file" )
131
- _ , _ = ctx .SaveFormFile (fileHeader , filepath )
131
+ _ , _ = ctx .SaveFormFile (fileHeader , filepath ) // $ FileSystemAccess=filepath
132
132
133
133
}
134
134
func Gin () {
135
135
router := gin .Default ()
136
136
router .POST ("/FormUploads" , func (c * gin.Context ) {
137
137
filepath := c .Query ("filepath" )
138
- c .File (filepath )
139
- http .ServeFile (c .Writer , c .Request , filepath )
140
- c .FileAttachment (filepath , "file name in response" )
138
+ c .File (filepath ) // $ FileSystemAccess=filepath
139
+ http .ServeFile (c .Writer , c .Request , filepath ) // $ FileSystemAccess=filepath
140
+ c .FileAttachment (filepath , "file name in response" ) // $ FileSystemAccess=filepath
141
141
file , _ := c .FormFile ("afile" )
142
- _ = c .SaveUploadedFile (file , filepath )
142
+ _ = c .SaveUploadedFile (file , filepath ) // $ FileSystemAccess=filepath
143
143
})
144
144
_ = router .Run ()
145
145
}
0 commit comments