Loading...
Searching...
No Matches
validatefilter.test.1.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing validatefilter service - input validation (security)
4 @details The filter_table in the IWANT input table must be a
5 well-formed LIBREF.DATASET. An invalid value aborts the service
6 before it reaches mp_filterstore. The abort shows up as a canceled
7 child job (an aborted service registers no webout).
8
9 The payload in test 1 resolves to a REAL table when the request
10 content is executed as macro code, so on a vulnerable service the
11 job completes, and only the validating service cancels it - the
12 assertion cannot pass against a service that does not validate.
13
14 <h4> SAS Macros </h4>
15 @li mpe_assert_abort.sas
16 @li mp_assert.sas
17 @li mpe_execute.sas
18 @li mf_getuniquefileref.sas
19
20 @sasjslint {"maxLineLength": 100}
21
22**/
23
24%let _program=&appLoc/services/public/validatefilter;
25
26/**
27 * Test 1 - macro content in filter_table must abort the service
28 */
29%let f1=%mf_getuniquefileref();
30data _null_;
31 file &f1 termstr=crlf;
32 put 'FILTER_TABLE:$41.';
33 put '%sysfunc(coalescec(&dclib..MPE_TABLES,))';
34run;
35
36%mpe_execute(&_program,
37 viyacontext=&defaultcontext,
38 inputfiles=&f1:iwant,
39 outref=web1,
40 outstatus=work.ab1,
41 failfast=0,
42 viyaresult=WEBOUT_TXT
43)
44
45%mpe_assert_abort(
46 desc=Macro content in filter_table aborts the service,
47 outstatus=work.ab1,
48 msg=Invalid filter_table
49)
50
51/**
52 * Test 2 - valid filter_table still stores a filter
53 */
54%let f2=%mf_getuniquefileref();
55data _null_;
56 file &f2 termstr=crlf;
57 put 'FILTER_TABLE:$41.';
58 put "&dclib..MPE_TABLES";
59run;
60%let f3=%mf_getuniquefileref();
61data _null_;
62 file &f3 termstr=crlf;
63 infile datalines4 dsd;
64 input;
65 put _infile_;
66datalines4;
67GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32. OPERATOR_NM:$10. RAW_VALUE:$4000.
68AND,AND,1,LIBREF,CONTAINS,"'DC'"
69AND,OR,2,DSN,=,"'MPE_LOCK_ANYTABLE'"
70;;;;
71run;
72
73%mpe_execute(&_program,
74 viyacontext=&defaultcontext,
75 inputfiles=&f2:iwant &f3:filterquery,
76 outlib=web2
77)
78
79%let nobs=0;
80proc sql noprint;
81select count(*) into: nobs from web2.result;
82quit;
83
84%mp_assert(
85 iftrue=(&nobs>0),
86 desc=Valid filter_table returns a filter result,
87 outds=work.test_results
88)
89
90/**
91 * dump results to the log for offline inspection
92 */
93data _null_;
94 set work.test_results;
95 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;
96run;