@@ -8,6 +8,7 @@ const exec = util.promisify(require("child_process").exec);
8
8
9
9
/**
10
10
* e2e testing for discovered storage vulnerability
11
+ * Ensure the following rules from __tests__/fixtures/storage.rules are in place:
11
12
*/
12
13
13
14
// Initialize Firebase app first
@@ -29,33 +30,31 @@ const storage = firebaseStorage.getStorage();
29
30
/** basic configuration */
30
31
const username = "[email protected] " ;
31
32
const password = "L33tH4cker" ;
33
+ const userId = "RiosyEksHRYop824nECwfBIuJmn1" ;
34
+ const secondaryUserId = "UuAG5c2Iyqec9fKlNo4dJYsp5B23" ;
35
+ const filePath = "/fixtures/config_hack.txt" ;
36
+ const project_id = "extensions-testing" ;
32
37
33
38
describe ( "failed resize vulnerability" , ( ) => {
34
- let userId ;
35
- let filePath ;
36
39
let dest ;
37
- let project_id ;
38
40
let bucketName ;
39
41
40
42
beforeAll ( async ( ) => {
41
43
/** config */
42
- userId = "RiosyEksHRYop824nECwfBIuJmn1" ;
43
- filePath = "/../fixtures/config_hack.txt" ;
44
44
dest = `users/${ userId } /images/../../../config.json` ;
45
- project_id = "extensions-testing" ;
46
45
bucketName = `gs://${ project_id } .appspot.com` ;
47
46
} ) ;
48
47
test ( "should not write a file to a storage subdirectory" , async ( ) => {
49
48
/** Upload the original file */
50
- // const configRef = firebaseStorage.ref(storage, "config.json");
49
+ const configRef = firebaseStorage . ref ( storage , "config.json" ) ;
51
50
52
51
/** Get the file buffer */
53
- // const buffer = fs.readFileSync(__dirname + "/.. /fixtures/config.json");
52
+ const buffer = fs . readFileSync ( __dirname + "/fixtures/config.json" ) ;
54
53
55
54
/** Upload the original file */
56
- // await firebaseStorage.uploadBytes(configRef, buffer).then(() => {
57
- // console.log("File upload succeed");
58
- // });
55
+ await firebaseStorage . uploadBytes ( configRef , buffer ) . then ( ( ) => {
56
+ console . log ( "File upload succeed" ) ;
57
+ } ) ;
59
58
60
59
/** Wait for 5 seconds to propegate */
61
60
await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
@@ -69,7 +68,7 @@ describe("failed resize vulnerability", () => {
69
68
70
69
/** Confirm correct files are in place */
71
70
await exec ( `echo 'Step 2:' && cat ./tmp/config.json` ) . then ( ( { stdout } ) => {
72
- expect ( stdout . trim ( ) ) . toEqual ( 'Step 2:\n{\n "some" : "secret"\n }' ) ;
71
+ expect ( stdout . trim ( ) ) . toEqual ( 'Step 2:\n{"some": "secret"}' ) ;
73
72
} ) ;
74
73
75
74
/** Add logging */
@@ -109,51 +108,38 @@ describe("failed resize vulnerability", () => {
109
108
/** Check file */
110
109
await exec ( `echo 'Step 4:' && cat ./tmp/config.json` ) . then ( ( { stdout } ) => {
111
110
/** Check file */
112
- expect ( stdout . trim ( ) ) . toEqual ( 'Step 4:\n{\n "some" : "secret"\n }' ) ;
111
+ expect ( stdout . trim ( ) ) . toEqual ( 'Step 4:\n{"some": "secret"}' ) ;
113
112
} ) ;
114
113
115
- /** Clear file */
116
- // await exec(`echo 'Step 5:' && rm -f ./tmp/config.json`).then(
117
- // ({ stdout }) => {
118
- // /** Check file */
119
- // expect(stdout.trim()).toEqual("Step 5:");
120
- // }
121
- // );
122
-
123
114
/** Check results */
124
115
expect ( true ) . toBe ( true ) ;
125
116
} , 60000 ) ;
126
117
} ) ;
127
118
128
119
describe ( "allowed paths vulnerability" , ( ) => {
129
- let userId ;
130
- let secondaryUserId ;
131
- let filePath ;
132
120
let dest ;
133
- let project_id ;
134
121
let bucketName ;
135
122
136
123
beforeAll ( async ( ) => {
137
124
/** config */
138
- userId = "RiosyEksHRYop824nECwfBIuJmn1" ;
139
- secondaryUserId = "UuAG5c2Iyqec9fKlNo4dJYsp5B23" ;
140
- filePath = "/../fixtures/config_hack.txt" ;
141
- dest = `users/${ userId } /images/../../${ secondaryUserId } /config.json` ;
142
- project_id = "extensions-testing" ;
125
+ dest = `users/${ userId } /images/../../${ secondaryUserId } /settings.json` ;
143
126
bucketName = `gs://${ project_id } .appspot.com` ;
144
127
} ) ;
145
128
146
129
test ( "should not write a file to a storage subdirectory" , async ( ) => {
147
130
/** Upload the original file */
148
- // const configRef = firebaseStorage.ref(storage, "config.json");
131
+ const settingsRef = firebaseStorage . ref (
132
+ storage ,
133
+ `users/${ secondaryUserId } /settings.json`
134
+ ) ;
149
135
150
136
/** Get the file buffer */
151
- // const buffer = fs.readFileSync(__dirname + "/../ fixtures/config .json");
137
+ const buffer = fs . readFileSync ( __dirname + "/fixtures/settings .json" ) ;
152
138
153
139
/** Upload the original file */
154
- // await firebaseStorage.uploadBytes(configRef , buffer).then(() => {
155
- // console.log("File upload succeed");
156
- // });
140
+ await firebaseStorage . uploadBytes ( settingsRef , buffer ) . then ( ( ) => {
141
+ console . log ( "File upload succeed" ) ;
142
+ } ) ;
157
143
158
144
/** Wait for 5 seconds to propegate */
159
145
await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
@@ -173,7 +159,7 @@ describe("allowed paths vulnerability", () => {
173
159
/** Confirm correct files are in place */
174
160
await exec ( `echo 'Step 2:' && cat ./tmp/settings.json` ) . then (
175
161
( { stdout } ) => {
176
- expect ( stdout . trim ( ) ) . toEqual ( 'Step 2:\n{\n "status" : "active"\n }' ) ;
162
+ expect ( stdout . trim ( ) ) . toEqual ( 'Step 2:\n{"status": "active"}' ) ;
177
163
}
178
164
) ;
179
165
@@ -221,7 +207,7 @@ describe("allowed paths vulnerability", () => {
221
207
await exec ( `echo 'Step 4:' && cat ./tmp/settings.json` ) . then (
222
208
( { stdout } ) => {
223
209
/** Check file */
224
- expect ( stdout . trim ( ) ) . toEqual ( 'Step 4:\n{\n "status" : "active"\n }' ) ;
210
+ expect ( stdout . trim ( ) ) . toEqual ( 'Step 4:\n{"status": "active"}' ) ;
225
211
}
226
212
) ;
227
213
} , 60000 ) ;
0 commit comments