Skip to content

Unsafe Jquery Plugin - Potential False Negative #7485

@Naman-ntc

Description

@Naman-ntc

Hi,
I was analyzing the results of unsafe jquery plugin query and I found an interesting example.
First, here is a code snippet marked vulnerable in query tests

(function(){
        $.fn.my_plugin = function my_plugin(element, options) {
                this.$element      = $(element);
                this.options       = $.extend({}, options);
                if (this.options.parent) this.$parent = $(this.options.parent) // NOT OK
        };
})

Here is (slightly modified) code I found in Collapse library which doesn't get marked as vulnerable

function ($) {
  var Library = function (element, options) {
    this.$element = $(element)
    this.options = $.extend({}, options)
    if (this.options.parent) {this.$parent = $(this.options.parent)}}
}(window.jQuery);

Also note that in the second example, the if statement acts as a barrier guard and makes it safe. Please let me know if it is indeed safe (and how!) or if it is a false negative

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions