-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[shared_preferences] Limit Android decoding (#8187)
When decoding stored preferences for `List<String>` support, only allow lists and strings to avoid potentially instantiating other object types.
- Loading branch information
1 parent
a4ac811
commit 15501ec
Showing
6 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/shared_preferences/shared_preferences_android/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.3.4 | ||
|
||
* Restrict types when decoding preferences. | ||
|
||
## 2.3.3 | ||
|
||
* Updates Java compatibility version to 11. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...droid/src/main/kotlin/io/flutter/plugins/sharedpreferences/StringListObjectInputStream.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.sharedpreferences | ||
|
||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.io.ObjectInputStream | ||
import java.io.ObjectStreamClass | ||
|
||
/** | ||
* An ObjectInputStream that only allows string lists, to prevent injected prefs from instantiating | ||
* arbitrary objects. | ||
*/ | ||
class StringListObjectInputStream(input: InputStream) : ObjectInputStream(input) { | ||
@Throws(ClassNotFoundException::class, IOException::class) | ||
override fun resolveClass(desc: ObjectStreamClass?): Class<*>? { | ||
val allowList = | ||
setOf( | ||
"java.util.Arrays\$ArrayList", | ||
"java.util.ArrayList", | ||
"java.lang.String", | ||
"[Ljava.lang.String;") | ||
val name = desc?.name | ||
if (name != null && !allowList.contains(name)) { | ||
throw ClassNotFoundException(desc.name) | ||
} | ||
return super.resolveClass(desc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters