|
| 1 | +<?xml version="1.0" encoding="UTF-8"?><record_update table="scan_linter_check"> |
| 2 | + <scan_linter_check action="INSERT_OR_UPDATE"> |
| 3 | + <active>true</active> |
| 4 | + <attributes/> |
| 5 | + <category>performance</category> |
| 6 | + <description>Providing an alternate, default value when calling gs.getProperty() helps mitigate risk of errors when property does not exist.</description> |
| 7 | + <documentation_url/> |
| 8 | + <finding_type>scan_finding</finding_type> |
| 9 | + <name>Provide alternate value when fetching Glide property</name> |
| 10 | + <priority>3</priority> |
| 11 | + <resolution_details>Consider providing an alternate. default value when using gs.getProperty() in case the property does not exist</resolution_details> |
| 12 | + <run_condition/> |
| 13 | + <score_max>100</score_max> |
| 14 | + <score_min>0</score_min> |
| 15 | + <score_scale>1</score_scale> |
| 16 | + <script><![CDATA[(function (engine) { |
| 17 | +
|
| 18 | + /** |
| 19 | + * The following to exclude certain tables like sys_script_execution_history |
| 20 | + * from being part of this scan is NOT possible here due to app scoping issues |
| 21 | + * (https://github.com/ServiceNowDevProgram/example-instancescan-checks/issues/9) |
| 22 | + */ |
| 23 | + //var excludedTablesProp = gs.getProperty(/* custom property name here */); |
| 24 | + //var excludedTables = excludedTablesProp.split(','); |
| 25 | + //var tableName = engine.current.getTableName(); |
| 26 | + //if (!new ArrayUtil().contains(excludedTables, tableName)) { |
| 27 | + |
| 28 | + engine.rootNode.visit(function(node) { |
| 29 | + |
| 30 | + // Find an occurrence of the getProperty function |
| 31 | + if (node.getNameIdentifier() && node.getNameIdentifier() === 'getProperty') { |
| 32 | +
|
| 33 | + // Walk up the AST tree to check if function is called on GlideSystem |
| 34 | + if (node.getParent().getTypeName() === 'GETPROP' |
| 35 | + && node.getParent().toSource() === 'gs.getProperty') { |
| 36 | + |
| 37 | + var argsProvided = 0; |
| 38 | + |
| 39 | + // Walk up to grandparent to check for the arguments provided |
| 40 | + node.getParent().getParent().visit(function(childnode) { |
| 41 | + // Case 1: Finds argument specified as a string, including when |
| 42 | + // default value is provided as number or boolean |
| 43 | + // eg. gs.getProperty('value1', 'value2'); |
| 44 | + if (childnode.getTypeName() === 'STRING' || childnode.getTypeName() === 'NUMBER' |
| 45 | + || childnode.getTypeName() === 'TRUE' || childnode.getTypeName() === 'FALSE') { |
| 46 | + argsProvided ++; |
| 47 | + } |
| 48 | + // Case 2: Find argument specified as a variable |
| 49 | + // eg. gs.getProperty(propertyName, defaultValue); |
| 50 | + else if (childnode.getTypeName() === 'NAME' && childnode.getNameIdentifier() |
| 51 | + && childnode.getNameIdentifier() !== 'gs' |
| 52 | + && childnode.getNameIdentifier() !== 'getProperty') { |
| 53 | + argsProvided++; |
| 54 | + } |
| 55 | +
|
| 56 | + }); |
| 57 | + if (argsProvided != 2) { |
| 58 | + engine.finding.incrementWithNode(node); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + }); |
| 63 | +
|
| 64 | +})(engine);]]></script> |
| 65 | + <short_description>Provide alternate value when fetching Glide property</short_description> |
| 66 | + <sys_class_name>scan_linter_check</sys_class_name> |
| 67 | + <sys_created_by>nia.mccash</sys_created_by> |
| 68 | + <sys_created_on>2021-10-27 13:39:00</sys_created_on> |
| 69 | + <sys_id>4986078c2f6330d05dcb59ab2799b6d9</sys_id> |
| 70 | + <sys_name>Provide alternate value when fetching Glide property</sys_name> |
| 71 | + <sys_package display_value="Example Instance Checks" source="x_appe_exa_checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_package> |
| 72 | + <sys_policy/> |
| 73 | + <sys_scope display_value="Example Instance Checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_scope> |
| 74 | + <sys_update_name>scan_linter_check_4986078c2f6330d05dcb59ab2799b6d9</sys_update_name> |
| 75 | + </scan_linter_check> |
| 76 | +</record_update> |
0 commit comments