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
最满意答案
首先,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).
相关问答
更多-
Content Provider是Repository Pattern的实现吗?(Is Content Provider an implementation of Repository Pattern?)[2023-02-28]
让我们尝试比较Martin Fowler(包括Dave Rice,Matthew Foemmel,Edward Hieatt,Robert Mee和Randy Stafford)的书籍“企业应用程序架构模式”中的知识库模式定义与我们对ContentProviders了解。 该书指出: 存储库使用类似集合的接口来访问域对象,从而在域和数据映射层之间进行调解。 重要的一点是accessing domain objects 。 所以乍一看似乎存储库模式只是用于访问(查询)数据。 但是,使用ContentProvi ... -
android - 没有内容提供者的CursorLoader&SQLite(android - CursorLoader & SQLite without Content Provider)[2023-09-20]
您在发布中提到的两个实现都提供了CursorLoader所有优点, 除了底层内容更改后接收通知的功能。 我最近一直在研究这个问题,我可以自信地告诉你,Android API目前并没有提供一种仅使用原始SQLiteDatabase (它只提供ContentResolver#notifyChange()和Cursor#setNotificationUri()方法,用于通知在特定通知Uri下注册的所有Cursor 。 也就是说,您现在的选择是: 自己实现一个能够在内容更改时从SQLiteDatabase接收通知的 ... -
SQLite DB尚未创建(SQLite DB not been created)[2022-04-04]
写下接收器代码而不是广播接收器代码,它将解决您的问题。 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; ... -
如何在Android内容提供商内部发出http请求?(How can I make an http request inside an android content provider?)[2022-07-07]
您缺少的组件是同步适配器 - 它们用于从内部服务(例如Web服务器)传输数据并将其插入到内容提供程序中。 它们还提供了在集中式帐户身份验证器中构建用户帐户和处理身份验证的功能 (尽管如果您不需要该功能,您当然可以构建存根身份验证器 )。 一旦构建了身份验证器/内容提供程序/同步适配器,就可以以编程方式创建一个帐户 (即使它只是名称的“后台同步”),然后运行同步适配器以使用数据加载内容提供程序。 对于第一次运行,您可能希望按需运行它 : Account account; // Account created ... -
本地SQLite DB的Android Content Provider:为什么?(Android Content Provider for local SQLite DB: why?)[2023-09-15]
首先,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 ...
-
Android - 如何将sqlite帮助程序类包装到内容提供程序中(Android - How to wrap a sqlite helper class into a content provider)[2019-09-25]
如果您不需要将数据的子集公开给设备上的其他应用程序(例如只读或单个表),则通常不需要内容提供商。 只需使用助手类访问您的数据,然后根据需要进行转换。 在您的情况下,您需要使用其中一个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 ... -
Android - Content Provider和已创建的数据库(Android - Content Provider and already created database)[2023-01-17]
如果您已经拥有数据库中所需的所有信息,则应使用它。 重复数据并不是很糟糕,但你也应该让两个数据库保持同步。 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 ...