https://github.com/cketti/safecontentresolver
A replacement for Android's ContentResolver that protects against the Surreptitious Sharing attack
https://github.com/cketti/safecontentresolver
android contentprovider contentresolver library security
Last synced: 5 months ago
JSON representation
A replacement for Android's ContentResolver that protects against the Surreptitious Sharing attack
- Host: GitHub
- URL: https://github.com/cketti/safecontentresolver
- Owner: cketti
- License: apache-2.0
- Created: 2016-02-29T05:32:31.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-06-24T01:04:27.000Z (over 5 years ago)
- Last Synced: 2025-07-26T19:42:16.056Z (6 months ago)
- Topics: android, contentprovider, contentresolver, library, security
- Language: Java
- Homepage:
- Size: 172 KB
- Stars: 40
- Watchers: 5
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SafeContentResolver
A replacement for Android's [`ContentResolver`](https://developer.android.com/reference/android/content/ContentResolver.html)
that protects against the *Surreptitious Sharing* attack.
## Surreptitious Sharing
Read all about it in the [corresponding blog post](https://www.ibr.cs.tu-bs.de/news/ibr/surreptitious-sharing-2016-04-04.xml).
## Usage
Replace all occurrences of [`ContentResolver.openInputStream()`](https://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri))
where URIs provided by other apps are opened with `SafeContentResolver.openInputStream()`.
`SafeContentResolver` will refuse to open `file://` URIs pointing to files belonging to your app and `content://` URIs
belonging to content providers of your app.
If you wish to allow access to certain content providers, add the following `` element to the appropriate
`` entries in your manifest:
```xml
```
The library comes in two flavors `safe-content-resolver-v14` and `safe-content-resolver-v21`. The former includes
native code to be able to invoke the `fstat` system call that is used to retrieve the owner of a file. Starting with
Lollipop (API 21) the framework includes the class [`Os`](https://developer.android.com/reference/android/system/Os.html)
to access this functionality. So `safe-content-resolver-v21` is free of native code and thus much smaller.
To retrieve an instance of `SafeContentResolver` use:
```java
SafeContentResolver safeContentResolver = SafeContentResolverCompat.newInstance(context);
```
If your `minSdkVersion` is 21 or higher you only need to include `safe-content-resolver-v21` and use the following code:
```java
SafeContentResolver safeContentResolver = SafeContentResolver.newInstance(context);
```
## Include the library
```groovy
implementation 'de.cketti.safecontentresolver:safe-content-resolver-v14:1.0.0'
```
Or, if you're using `minSdkVersion` 21 or higher:
```groovy
implementation 'de.cketti.safecontentresolver:safe-content-resolver-v21:1.0.0'
```
## Native code
`safe-content-resolver-v14` contains native code for the following ABIs:
* armeabi-v7a
* arm64-v8a
* x86
* x86_64
If you don't want to include all of them in your APK you might want to look into
[ABIs Splits](https://developer.android.com/studio/build/configure-apk-splits.html#configure-abi-split).
## License
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.