Is it possible to store javascript in a database?

我只是一个虾纸丫 提交于 2019-12-10 03:48:55

问题


I have an idea for a web application where a user can submit Javascript code that can then be served up to other users. I'm wondering what's the best way of going about this. Is it possible to store the Javascript in a database and then serve it up to users as they request it? I would also like to be able to attach metadata to each piece of code: name, user ratings, etc., so a database seems like the natural solution to my somewhat underinformed mind. I'm looking at using Rails on the backend with MongoDB.


回答1:


Javascript is a string of text. Databases can store strings of text. Hence, databases can store Javascript.

Unless you have some specific idea I'm missing though, I wholly agree with @Aircule's sentiment.

Wow, I don't think I've seen a worse idea in ages.




回答2:


Yes, it seems like you've got a grasp of what is required. Just be careful not to execute the arbitrary code - you could be entering a world of XSS hurt.

Unless you're going to be getting millions of hits a minute, any database or framework will be fine.




回答3:


I highly recommend reading up on XSS and CSRF. (shameless plug, i blogged a high level overview here) It is hard enough to prevent these sort of things when you are actively trying to look out for them, sanitizing js would be an absolute nightmare.



来源:https://stackoverflow.com/questions/3146069/is-it-possible-to-store-javascript-in-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!