Loading...
Searching...
No Matches
getrawdata.test.1.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing getrawdata service - input validation (security)
4 @details table must be a well-formed LIBREF.DATASET (the trailing
5 format-catalog suffix is permitted), filter must be an integer and
6 type one of the supported download types. An invalid value aborts
7 the service before any request content can execute. The abort is
8 asserted from the child job state: the payloads either resolve to a
9 real table when executed as macro code, or write a file outside the
10 WORK directory (verified by live probe) - so on the vulnerable
11 service the job completes, and only the validating service cancels
12 it. The assertion cannot pass against a service that does not
13 validate.
14
15 <h4> SAS Macros </h4>
16 @li mp_assert.sas
17 @li mx_execute.sas
18
19**/
20
21%let _program=&appLoc/services/public/getrawdata;
22
23/**
24 * Test 1 - macro content in table must abort the service
25 * (the payload resolves to a real table when executed as macro code)
26 */
27data work.params1;
28 length name $32 value $1000;
29 name='type';value='CSV';output;
30 name='table';value='%sysfunc(coalescec(&mpelib..MPE_X_TEST,))';output;
31 name='filter';value='0';output;
32run;
33
34%mx_execute(&_program,
35 viyacontext=&defaultcontext,
36 inputparams=work.params1,
37 outref=web1,
38 viyaresult=WEBOUT_TXT
39)
40
41%let abort1=0;
42data _null_;
43 set work.results;
44 if state='canceled' then call symputx('abort1',1);
45run;
46
47%mp_assert(
48 iftrue=(&abort1=1),
49 desc=Macro content in table aborts the service,
50 outds=work.test_results
51)
52
53/**
54 * Test 2 - sql injection in filter must abort the service
55 */
56data work.params2;
57 length name $32 value $1000;
58 name='type';value='CSV';output;
59 name='table';value="&dclib..MPE_X_TEST";output;
60 name='filter';value='0 or 1=1';output;
61run;
62
63%mx_execute(&_program,
64 viyacontext=&defaultcontext,
65 inputparams=work.params2,
66 outref=web2,
67 viyaresult=WEBOUT_TXT
68)
69
70%let abort2=0;
71data _null_;
72 set work.results;
73 if state='canceled' then call symputx('abort2',1);
74run;
75
76%mp_assert(
77 iftrue=(&abort2=1),
78 desc=SQL injection in filter aborts the service,
79 outds=work.test_results
80)
81
82/**
83 * Test 3 - path traversal in table must abort the service
84 * (verified by live probe: on a vulnerable service this writes
85 * ../SECPROBE.csv outside the WORK directory and completes)
86 */
87data work.params3;
88 length name $32 value $1000;
89 name='type';value='CSV';output;
90 name='table';value='../secprobe';output;
91 name='filter';value='0';output;
92run;
93
94%mx_execute(&_program,
95 viyacontext=&defaultcontext,
96 inputparams=work.params3,
97 outref=web3,
98 viyaresult=WEBOUT_TXT
99)
100
101%let abort3=0;
102data _null_;
103 set work.results;
104 if state='canceled' then call symputx('abort3',1);
105run;
106
107%mp_assert(
108 iftrue=(&abort3=1),
109 desc=Path traversal in table aborts the service,
110 outds=work.test_results
111)
112
113/**
114 * Test 4 - the valid request must still work (positive control)
115 */
116data work.params4;
117 length name $32 value $1000;
118 name='type';value='CSV';output;
119 name='table';value="&dclib..MPE_X_TEST";output;
120 name='filter';value='0';output;
121run;
122
123%mx_execute(&_program,
124 viyacontext=&defaultcontext,
125 inputparams=work.params4,
126 outref=web4,
127 viyaresult=WEBOUT_TXT
128)
129
130%let ok4=0;
131data _null_;
132 infile web4;
133 input;
134 if _infile_=:'PRIMARY_KEY_FIELD' then do;
135 call symputx('ok4',1);
136 stop;
137 end;
138run;
139
140%mp_assert(
141 iftrue=(&ok4=1),
142 desc=Valid table request still returns data,
143 outds=work.test_results
144)
145
146/**
147 * dump results to the log for offline inspection
148 */
149data _null_;
150 set work.test_results;
151 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;
152run;