Loading...
Searching...
No Matches
getdiffs.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing getdiffs service - input validation (security)
4 @details The libds, table and stp_diffs_csv request params must be
5 well-formed before they reach the access check and the staging file
6 path. An invalid value aborts the service, which shows up as a
7 canceled child job (an aborted service registers no webout).
8
9 A real load is staged first (stagedata) and a diffs csv written into
10 the staging directory, so every payload below resolves to that REAL
11 file when executed - on a vulnerable service the job completes, and
12 only the validating service cancels it. The assertions cannot pass
13 against a service that does not validate.
14
15 <h4> SAS Macros </h4>
16 @li mpe_assert_abort.sas
17 @li mp_assert.sas
18 @li mpe_execute.sas
19 @li mx_execute.sas
20 @li mf_getuniquefileref.sas
21
22**/
23
24%let _program=&appLoc/services/auditors/getdiffs;
25
26/**
27 * Stage a real load so a real staging directory exists
28 */
29data work.sascontroltable;
30 action='LOAD';
31 message="getdiffs test prep";
32 libds="&dclib..MPE_X_TEST";
33 output;
34 stop;
35run;
36
37proc sql noprint;
38select max(primary_key_field) into: maxpk
39 from &dclib..mpe_x_test;
40quit;
41
42data work.jsdata;
43 set &dclib..mpe_x_test(rename=(
44 some_date=dt2 SOME_DATETIME=dttm2 some_time=tm2)
45 );
46 some_date=put(dt2,date9.);
47 SOME_DATETIME=put(dttm2,datetime19.);
48 some_time=put(tm2,time.);
49 drop dt2 dttm2 tm2;
50 if _n_=1 then do;
51 _____DELETE__THIS__RECORD_____='No';
52 some_char='getdiffs security test';
53 some_num=&maxpk+1;
54 end;
55 else stop;
56run;
57
58%mx_execute(&appLoc/services/editors/stagedata,
59 viyacontext=&defaultcontext,
60 inputdatasets=work.jsdata work.sascontroltable,
61 outlib=webstage,
62 mdebug=&sasjs_mdebug
63)
64
65%let stagetest=0;
66data _null_;
67 set webstage.sasparams;
68 putlog (_all_)(=);
69 if status='SUCCESS' then call symputx('stagetest',1);
70 call symputx('loadref',dsid);
71run;
72
73%mp_assert(
74 iftrue=(&stagetest=1 and &syscc=0),
75 desc=stagedata succeeded in getdiffs prep,
76 outds=work.test_results
77)
78
79/**
80 * Write the diffs csv into the real staging directory
81 */
82%let diffscsv=tempDiffs_secrev.csv;
83data _null_;
84 file "&dc_staging_area/&loadref./&diffscsv";
85 put 'SOME_CHAR,_____STATUS_____';
86 put 'getdiffs security test,UPDATED';
87run;
88
89/**
90 * Test 1 - the mpe_accesscheck SQL injection payload in libds must
91 * abort the service (validation fires before the authz query, so
92 * the authz bypass cannot happen). The payload is sent through the
93 * sasjs table channel (BrowserParams) like the frontend does - the
94 * raw-quote form is masked in plain URL params on this platform.
95 */
96%let fb1=%mf_getuniquefileref();
97data _null_;
98 file &fb1 termstr=crlf;
99 length _row $400.;
100 put 'TABLE:$41. STP_DIFFS_CSV:$100. libds:$41.';
101 _row=cats(symget('loadref'),',',symget('diffscsv'),',',
102 'SOMELIB.SOMEDS',"'22'x"," or ","'22'x",'1',"'22'x",' ne ',"'22'x",'2');
103 put _row;
104run;
105
106%mpe_execute(&_program,
107 viyacontext=&defaultcontext,
108 inputfiles=&fb1:BrowserParams,
109 outref=web1,
110 outstatus=work.ab1,
111 failfast=0,
112 viyaresult=WEBOUT_TXT
113)
114
115%mpe_assert_abort(
116 desc=SQL injection payload in libds aborts the service,
117 outstatus=work.ab1,
118 msg=Invalid libds
119)
120
121/**
122 * Test 2 - path traversal in table must abort the service (the
123 * payload resolves to the real staged file through a .. detour)
124 */
125data _null_;
126 length _dir $512;
127 _dir=scan(symget('dc_staging_area'),-1,'/');
128 call symputx('travtable',cats('../',_dir,'/','&loadref'));
129run;
130
131%let fb2=%mf_getuniquefileref();
132data _null_;
133 file &fb2 termstr=crlf;
134 put 'TABLE:$41. STP_DIFFS_CSV:$100. libds:$41.';
135 put "&travtable.,&diffscsv.,&dclib..MPE_X_TEST";
136run;
137
138%mpe_execute(&_program,
139 viyacontext=&defaultcontext,
140 inputfiles=&fb2:BrowserParams,
141 outref=web2,
142 outstatus=work.ab2,
143 failfast=0,
144 viyaresult=WEBOUT_TXT
145)
146
147%mpe_assert_abort(
148 desc=Path traversal in table aborts the service,
149 outstatus=work.ab2,
150 msg=Invalid table
151)
152
153/**
154 * Test 3 - path traversal in stp_diffs_csv must abort the service
155 */
156%let fb3=%mf_getuniquefileref();
157data _null_;
158 file &fb3 termstr=crlf;
159 put 'TABLE:$41. STP_DIFFS_CSV:$100. libds:$41.';
160 put "&loadref.,../&loadref./&diffscsv.,&dclib..MPE_X_TEST";
161run;
162
163%mpe_execute(&_program,
164 viyacontext=&defaultcontext,
165 inputfiles=&fb3:BrowserParams,
166 outref=web3,
167 outstatus=work.ab3,
168 failfast=0,
169 viyaresult=WEBOUT_TXT
170)
171
172%mpe_assert_abort(
173 desc=Path traversal in stp_diffs_csv aborts the service,
174 outstatus=work.ab3,
175 msg=Invalid stp_diffs_csv
176)
177
178/**
179 * dump results to the log for offline inspection
180 */
181data _null_;
182 set work.test_results;
183 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;
184run;