john chen
john chen

Reputation: 85

How prevent DOM XSS

I have function to get radio button value.

var val = $('input[name="test_'+ id + 
'"]:checked').val();

but it cause DOM XSS. How do I refactor to prevent XSS?

thanks.

Upvotes: 2

Views: 577

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 371193

This does not have an XSS vulnerability except in extremely ancient versions of jQuery, so it's probably not something to worry about.

Avoiding jQuery and using querySelector will work though.

const val = document.querySelector('input[name="test_'+ id + '"]:checked').value;

Upvotes: 1

Related Questions