javascript - Security issues with reading a JS array? -


i'm building website have js multi-dimensional array in .js file in scripts folder on server. in array video embed codes (vimeo iframes) , additional strings composers, players , piece names. there 1000 videos in array.

var videos = [ ['embed code', 'composer name', 'player name', 'piece name'], ['embed code', 'composer name', 'player name', 'piece name']...]; 

there search text box users specific searches composer, player, etc. jquery script iterate through each inner array find matches user's query , present them on page. this:

function getarray(video) {      if (campyear === video[j]) {        var pos = video.indexof(video[j]);                           $('#searcharea').append('<td>' + video[(pos - pos)] + '</td><td><h3>composer: ' + video[(pos -pos) + 1] + '</h3><br><h3>player: ' + video[(pos - pos) + 2] + '</h3><br><h3>piece: ' + video[(pos - pos) + 3] + '</h3></td>');      }        else          noresultcount++;                            if (campyear === video[j] && count % 2 === 0)         $('#searcharea').append('</tr><tr>');        if (campyear === video[j])         count++;        if (i === videos.lenght && j === 4)         $('#searcharea').append('</table>');        if (noresultcount === videos.length * 5)          $('#searcharea').html("<h4>no results found " + yearvalue + " " + buttonvalue + ". not camps have videos every year.</h4>");         $('#searcharea').fadein(500);      } // end of getarray() ... ... ...  (i = 0; < videos.length; i++) {         (j = 0; j < 5; j++) {         getarray(videos[i]);                    }       } 

i know there security issues traditional sql databases , php need considered, in case should concerned threats data or website? thought script can read data , print there wasn't do, i'm not sure. data isn't sensitive.

thanks time.

the issue if can alter file before gets read in, can inject javascript code it. 1 way alter file hack server, taking on proxies don't have touch machine @ all. they have somehow trick clients going through proxy, can't stop happening.

the easiest fix use json file instead of javascript file. json's syntax close syntax used js literals: far can see example, changes you'd need make file rid of "var videos =" @ start , swap single-quotes double-quotes. in code, exchange whatever works effect:

// assume getjs() grabs javascript file // , returns string text of file. var videocode = getjs(); eval(videocode); 

...for works this:

// assume getjsondata() grabs json // , returns string text of file. jsondata = getjsondata(); var videos = json.parse(jsondata); 

note we're using json.parse (which has polyfills old browsers) instead of eval. because puts code through dedicated json parser instead of javascript one. json doesn't know how deal code, if attacker tries inject code changing file, changed code won't work, because json won't know it. don't want app stop in middle, it's better letting attacker take over.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -