Skip to content

Commit 7164752

Browse files
Xinzhu Caifacebook-github-bot
authored andcommitted
5/n Check protected mode is applied before filtering the sensitive params
Summary: **Context** Protected Mode is introduced for finance / health related apps integrity purpose last year. It will drop ALL the non-standard parameters of the event. Sensitive parameters filtering will drop the particular parameters for each event based on the config fetched from server for all apps (eventually). Given that we never need to filter the standard parameters, we check if the protected mode is applied before processing the sensitive param filter. **Change in this diff** - Add a check of protected mode is applied Reviewed By: KylinChang Differential Revision: D53818572 fbshipit-source-id: 360d2b173347568c44faf2d43683a05be00e727a
1 parent 292fe7d commit 7164752

File tree

4 files changed

+251
-214
lines changed

4 files changed

+251
-214
lines changed

facebook-core/src/main/java/com/facebook/appevents/AppEvent.kt

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.facebook.FacebookException
1515
import com.facebook.LoggingBehavior
1616
import com.facebook.appevents.eventdeactivation.EventDeactivationManager.processDeprecatedParameters
1717
import com.facebook.appevents.integrity.IntegrityManager
18+
import com.facebook.appevents.integrity.ProtectedModeManager.protectedModeIsApplied
1819
import com.facebook.appevents.integrity.RedactedEventsManager
1920
import com.facebook.appevents.integrity.SensitiveParamsManager.processFilterSensitiveParams
2021
import com.facebook.appevents.internal.AppEventUtility.bytesToHex
@@ -43,27 +44,27 @@ class AppEvent : Serializable {
4344

4445
@Throws(JSONException::class, FacebookException::class)
4546
constructor(
46-
contextName: String,
47-
eventName: String,
48-
valueToSum: Double?,
49-
parameters: Bundle?,
50-
isImplicitlyLogged: Boolean,
51-
isInBackground: Boolean,
52-
currentSessionId: UUID?
47+
contextName: String,
48+
eventName: String,
49+
valueToSum: Double?,
50+
parameters: Bundle?,
51+
isImplicitlyLogged: Boolean,
52+
isInBackground: Boolean,
53+
currentSessionId: UUID?
5354
) {
5455
isImplicit = isImplicitlyLogged
5556
inBackground = isInBackground
5657
name = eventName
5758
jsonObject =
58-
getJSONObjectForAppEvent(contextName, eventName, valueToSum, parameters, currentSessionId)
59+
getJSONObjectForAppEvent(contextName, eventName, valueToSum, parameters, currentSessionId)
5960
checksum = calculateChecksum()
6061
}
6162

6263
private constructor(
63-
jsonString: String,
64-
isImplicit: Boolean,
65-
inBackground: Boolean,
66-
checksum: String?
64+
jsonString: String,
65+
isImplicit: Boolean,
66+
inBackground: Boolean,
67+
checksum: String?
6768
) {
6869
jsonObject = JSONObject(jsonString)
6970
this.isImplicit = isImplicit
@@ -79,10 +80,10 @@ class AppEvent : Serializable {
7980
// for old events we don't have a checksum
8081
val isChecksumValid: Boolean
8182
get() =
82-
if (checksum == null) {
83-
// for old events we don't have a checksum
84-
true
85-
} else calculateChecksum() == checksum
83+
if (checksum == null) {
84+
// for old events we don't have a checksum
85+
true
86+
} else calculateChecksum() == checksum
8687

8788
private fun getJSONObjectForAppEvent(
8889
contextName: String,
@@ -134,26 +135,28 @@ class AppEvent : Serializable {
134135
val value = parameters[key]
135136
if (value !is String && value !is Number) {
136137
throw FacebookException(
137-
String.format(
138-
"Parameter value '%s' for key '%s' should be a string" + " or a numeric type.",
139-
value,
140-
key))
138+
String.format(
139+
"Parameter value '%s' for key '%s' should be a string" + " or a numeric type.",
140+
value,
141+
key))
141142
}
142143
paramMap[key] = value.toString()
143144
}
144-
processFilterSensitiveParams(paramMap as MutableMap<String, String?>, name)
145+
if (!protectedModeIsApplied(parameters)) {
146+
processFilterSensitiveParams(paramMap as MutableMap<String, String?>, name)
147+
}
145148
IntegrityManager.processParameters(paramMap)
146149
processParameters(paramMap as MutableMap<String, String?>, name)
147150
processDeprecatedParameters(paramMap as MutableMap<String, String?>, name)
148151
return paramMap
149152
}
150-
153+
151154
internal class SerializationProxyV2
152155
constructor(
153-
private val jsonString: String,
154-
private val isImplicit: Boolean,
155-
private val inBackground: Boolean,
156-
private val checksum: String?
156+
private val jsonString: String,
157+
private val isImplicit: Boolean,
158+
private val inBackground: Boolean,
159+
private val checksum: String?
157160
) : Serializable {
158161
@Throws(JSONException::class, ObjectStreamException::class)
159162
private fun readResolve(): Any {
@@ -172,10 +175,10 @@ class AppEvent : Serializable {
172175

173176
override fun toString(): String {
174177
return String.format(
175-
"\"%s\", implicit: %b, json: %s",
176-
jsonObject.optString("_eventName"),
177-
isImplicit,
178-
jsonObject.toString())
178+
"\"%s\", implicit: %b, json: %s",
179+
jsonObject.optString("_eventName"),
180+
isImplicit,
181+
jsonObject.toString())
179182
}
180183

181184
private fun calculateChecksum(): String {
@@ -215,11 +218,11 @@ class AppEvent : Serializable {
215218
identifier = "<None Provided>"
216219
}
217220
throw FacebookException(
218-
String.format(
219-
Locale.ROOT,
220-
"Identifier '%s' must be less than %d characters",
221-
identifier,
222-
MAX_IDENTIFIER_LENGTH))
221+
String.format(
222+
Locale.ROOT,
223+
"Identifier '%s' must be less than %d characters",
224+
identifier,
225+
MAX_IDENTIFIER_LENGTH))
223226
}
224227
var alreadyValidated: Boolean
225228
synchronized(validatedIdentifiers) {
@@ -230,11 +233,11 @@ class AppEvent : Serializable {
230233
synchronized(validatedIdentifiers) { validatedIdentifiers.add(identifier) }
231234
} else {
232235
throw FacebookException(
233-
String.format(
234-
"Skipping event named '%s' due to illegal name - must be " +
235-
"under 40 chars and alphanumeric, _, - or space, and " +
236-
"not start with a space or hyphen.",
237-
identifier))
236+
String.format(
237+
"Skipping event named '%s' due to illegal name - must be " +
238+
"under 40 chars and alphanumeric, _, - or space, and " +
239+
"not start with a space or hyphen.",
240+
identifier))
238241
}
239242
}
240243
}

0 commit comments

Comments
 (0)