Skip to content

Commit c95dbcb

Browse files
Merge pull request #436 from purplecabbage/ValidateCallbackId
[android] Prevent malformed callbackId from reaching app cordova view
2 parents 92243cd + 6861084 commit c95dbcb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/android/InAppChromeClient.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public boolean onJsPrompt(WebView view, String url, String message, String defau
104104
if(defaultValue.startsWith("gap-iab://")) {
105105
PluginResult scriptResult;
106106
String scriptCallbackId = defaultValue.substring(10);
107-
if (scriptCallbackId.startsWith("InAppBrowser")) {
107+
if (scriptCallbackId.matches("^InAppBrowser[0-9]{1,10}$")) {
108108
if(message == null || message.length() == 0) {
109109
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
110110
} else {
@@ -118,9 +118,14 @@ public boolean onJsPrompt(WebView view, String url, String message, String defau
118118
result.confirm("");
119119
return true;
120120
}
121+
else {
122+
// Anything else that doesn't look like InAppBrowser0123456789 should end up here
123+
LOG.w(LOG_TAG, "InAppBrowser callback called with invalid callbackId : "+ scriptCallbackId);
124+
result.cancel();
125+
return true;
126+
}
121127
}
122-
else
123-
{
128+
else {
124129
// Anything else with a gap: prefix should get this message
125130
LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
126131
result.cancel();

0 commit comments

Comments
 (0)