How to fix Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) in below js line

43 Views Asked by At
ajaxCall : function(s, o) {
            $.ajax({
                type : "GET",
                url : s.options.data,
                dataType : "json",
                async : false,
                success : function(data) {
                    var result = data;
                    $.each(result, function(key, value) {
                        if ($('[data-dd-value="' + value + '"]', o.dd).length <= 0) {
                            $(".search-dd-menu", o.dd).append('<li tabindex="0"><a class="list-ref" href="#" data-dd-key="' + key + '" data-dd-value="' + value + '">' + value + '</a></li>');
                            if (s.options.multiSelect) {
                                $(".search-dd-menu", o.dd).children('li').addClass('multi-select');
                                $('.chosen-choices', o.dd).addClass('multi-select');
                            }
                        }
                    });

if ($('[data-dd-value="' + value + '"]', o.dd).length <= 0) {

This line is showing Veracode issue but i am unable to resolve it. I found the solution below but i am not sure is it the good solution or not. please someone guide me on this as i am new to js and veracode issues

I tried like

if (ESAPI.encoder().encodeForJavascript($('[data-dd-value="' + value + '"]', o.dd).length <= 0) {
0

There are 0 best solutions below