首页 \ 问答 \ javascript eval()和安全性(javascript eval() and security)

javascript eval()和安全性(javascript eval() and security)

developer.mozilla.org说:

不要不必要地使用eval! eval()是一个危险的函数,它执行它以调用者的特权传递的代码。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

例如,任何恶意用户都可以打开chrome调试器,并修改正在执行的javascript代码。 所以他可以把自己的功能放到执行等。

一般有“安全javascript代码”这样的东西吗?


developer.mozilla.org says:

Don't use eval needlessly! eval() is a dangerous function, which executes the code it's passed with the privileges of the caller.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

Any malicious user can turn on chrome debugger for example, and modify javascript code that is being executed. So he can put his own functions to be executed etc.

Is there such thing as "secure javascript code" in general?


原文:https://stackoverflow.com/questions/39058482
更新时间:2023-07-20 16:07

最满意答案

首先,Sync API不仅仅是从服务器加载数据。 它控制将同步更新与整个系统中的其他应用程序同步批处理,​​在运行之前确保连接,并优化整个系统的电池寿命(如定期运行同步适配器使用同步适配器指南传输数据时所述)。

其次,使用Content Provider可以非常轻松地利用Loaders框架(也可以在支持库中找到)和CursorLoader ,它允许您的UI在Content Provider中作为数据更改自动更新。 这可以大大减少整个活动所需的样板量。

如果Content Provider本身的样板是一个问题,那么您当然可以使用诸如ProviGen之类的 Annotation框架为自动生成绝大多数内容提供程序。

Android中还有一些功能只能在内容提供商的帮助下完成,包括自定义搜索建议和将应用程序专用文件共享到其他应用程序(尽管扩展ContentProvider的帮助程序FileProvider类是您需要的大部分内容。那)。

UI测试可以变得更加容易,您可以使用提供的MockContentProvider来模拟特定的数据集,而无需更改您的活动代码(假设它当然只是从Content Provider加载数据)。


First, the Sync API does much more than just loading data from your server. It controls batching your sync updates with other applications' syncs across the entire system, ensures connectivity before running, and optimizes for battery life across the entire system (as explained when running Sync Adapters periodically and in the transferring data using sync adapters guide).

Second, using a Content Provider allows you to very easily take advantage of the Loaders framework (available in the Support Library as well) and CursorLoader which allows your UI to automatically update as data changes in the Content Provider. This can vastly reduce the amount of boilerplate required throughout your Activities.

If the boilerplate of the Content Provider itself is an issue, then you can certainly use Annotation frameworks such as ProviGen to automatically generate the vast majority of a Content Provider for you.

There are also some features in Android that can only be done with the help of a Content Provider, including custom search suggestions and sharing app private files to other apps (although the helper FileProvider class that extends ContentProvider is most of what you'd need for that).

UI testing can be made much easier as well as you can use the provided MockContentProvider to mock up specific sets of data without having to change your Activity code (assuming it is only loading data from the Content Provider of course).

相关问答

更多
  • 让我们尝试比较Martin Fowler(包括Dave Rice,Matthew Foemmel,Edward Hieatt,Robert Mee和Randy Stafford)的书籍“企业应用程序架构模式”中的知识库模式定义与我们对ContentProviders了解。 该书指出: 存储库使用类似集合的接口来访问域对象,从而在域和数据映射层之间进行调解。 重要的一点是accessing domain objects 。 所以乍一看似乎存储库模式只是用于访问(查询)数据。 但是,使用ContentProvi ...
  • 您在发布中提到的两个实现都提供了CursorLoader所有优点, 除了底层内容更改后接收通知的功能。 我最近一直在研究这个问题,我可以自信地告诉你,Android API目前并没有提供一种仅使用原始SQLiteDatabase (它只提供ContentResolver#notifyChange()和Cursor#setNotificationUri()方法,用于通知在特定通知Uri下注册的所有Cursor 。 也就是说,您现在的选择是: 自己实现一个能够在内容更改时从SQLiteDatabase接收通知的 ...
  • 写下接收器代码而不是广播接收器代码,它将解决您的问题。 public class logs extends BroadcastReceiver { SQLiteDatabase calllog; String get_number, get_type, get_duration, Current_time, get_date,logTypecode; Handler hand = new Handler(); Cursor cursor; LocalDb dbex; ...
  • 您缺少的组件是同步适配器 - 它们用于从内部服务(例如Web服务器)传输数据并将其插入到内容提供程序中。 它们还提供了在集中式帐户身份验证器中构建用户帐户和处理身份验证的功能 (尽管如果您不需要该功能,您当然可以构建存根身份验证器 )。 一旦构建了身份验证器/内容提供程序/同步适配器,就可以以编程方式创建一个帐户 (即使它只是名称的“后台同步”),然后运行同步适配器以使用数据加载内容提供程序。 对于第一次运行,您可能希望按需运行它 : Account account; // Account created ...
  • 首先,Sync API不仅仅是从服务器加载数据。 它控制将同步更新与整个系统中的其他应用程序同步批处理,在运行之前确保连接,并优化整个系统的电池寿命(如定期运行同步适配器和使用同步适配器指南传输数据时所述)。 其次,使用Content Provider可以非常轻松地利用Loaders框架(也可以在支持库中找到)和CursorLoader ,它允许您的UI在Content Provider中作为数据更改自动更新。 这可以大大减少整个活动所需的样板量。 如果Content Provider本身的样板是一个问题, ...
  • 创建数据库时,您要指定数据库名称(例如products.db )。 如果您的应用程序包名称是com.example.yourapplicationpackage,则可以使用以下路径访问该文件: /data/data/com.example.yourapplicationpackage/databases/products.db 然后,您可以像处理任何其他文件一样将该文件发送到服务器(使用POST请求)。 在服务器端,您需要类来读取SQLite 3数据库文件,这应该不难找到。 When you create ...
  • 如果您不需要将数据的子集公开给设备上的其他应用程序(例如只读或单个表),则通常不需要内容提供商。 只需使用助手类访问您的数据,然后根据需要进行转换。 在您的情况下,您需要使用其中一个XML API来生成服务器所需的文档。 但是,如果您正在寻找(例如JAXB等其他Java平台),那么没有什么可以自动为您执行此操作。 If you don't need to expose a subset of your data to other apps on the device (say read only, or a ...
  • 如果您已经拥有数据库中所需的所有信息,则应使用它。 重复数据并不是很糟糕,但你也应该让两个数据库保持同步。 If you already have all the information you need in your DB, you should use it. It wouldn't be just bad enough to duplicate data, but you should also keep the two DB's in synch.
  • 您的数据库未从Activity扩展,因此无法访问此方法。 您应该创建从Activity接收Context作为参数的构造函数。 你的代码应该是这样的: private Context ctx; public contactdb(Context ctx) { this.ctx = ctx; } 在您的Activity您应该创建如下的实例: contactdb db = new contactdb(this); 请从大写字母命名您的课程。 研究一下java中的代码约定。 Your database ...
  • 我的主要问题是尝试创建一个链接到我的数据库的URI。 现在,您的ListProvider.CONTENT_URI将使用您的UriMatcher在ListProvider.CONTENT_URI匹配。 而您的ListProvider正在使用您的dataStore.TABLE_NAME_INFOTABLE ,这是您数据库中唯一的表。 因此,您可以使用Activity的ContentResolver直接使用ContentProvider ,代码如下: getContentResolver().query(Lis ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)