{"id":8172,"date":"2021-07-21T21:35:41","date_gmt":"2021-07-22T02:35:41","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=8172"},"modified":"2021-08-19T10:55:54","modified_gmt":"2021-08-19T15:55:54","slug":"fortify-on-demand-remediation-json-injection","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=8172","title":{"rendered":"Fortify on Demand Remediation &#8211; JSON Injection"},"content":{"rendered":"<p>This vulnerability occurs when you write unvalidated input to JSON. A common scenario would be using an Ajax call to pass a string of data to a file and then decoding that string to JSON within the file.<\/p>\n<p>To get around the Foritfy scanning requirements you have to use base64 encoding on the string before sending it through the Ajax call:<\/p>\n<blockquote>\n<pre>var update = $.ajax({\r\n    type: \"POST\",\r\n    url: \"SFPNotesUpdate\/..\/php\/validate_notes.php\",\r\n    data: { tableData: btoa(JSON.stringify(HotRegisterer.getInstance('myhot').getData())) },\r\n    dataType: 'json'\r\n});<\/pre>\n<\/blockquote>\n<p>When reading the input to decode the JSON string to an array you have to perform these actions in order:<\/p>\n<ul>\n<li>base64_decode the input string<\/li>\n<li>sanitize the input string<\/li>\n<li>decode the JSON string to an array<\/li>\n<\/ul>\n<blockquote>\n<pre>$tbl_data = json_decode(filter_var(base64_decode($_POST['tableData']), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES), true);<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This vulnerability occurs when you write unvalidated input to JSON. A common scenario would be using an Ajax call to pass a string of data to a file and then decoding that string to JSON within the file. To get around the Foritfy scanning requirements you have to use base64 encoding on the string before &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[45,1437,856,35,69,1329],"class_list":["post-8172","post","type-post","status-publish","format-standard","hentry","category-coding","tag-coding","tag-fortify-on-demand","tag-javascript","tag-php","tag-security","tag-web-coding"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8172"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8172\/revisions"}],"predecessor-version":[{"id":8173,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8172\/revisions\/8173"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}