mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
Fixing CB-343: We need to respect the whitelist
This commit is contained in:
parent
dc93556ef0
commit
04b3e4d847
@ -1333,7 +1333,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
boolean isUrlWhiteListed(String url) {
|
||||
public boolean isUrlWhiteListed(String url) {
|
||||
|
||||
// Check to see if we have matched url previously
|
||||
if (whiteListCache.get(url) != null) {
|
||||
|
@ -416,32 +416,39 @@ public class FileTransfer extends Plugin {
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
// connect to server
|
||||
URL url = new URL(source);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
if(this.ctx.isUrlWhiteListed(source))
|
||||
{
|
||||
URL url = new URL(source);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
|
||||
Log.d(LOG_TAG, "Download file:" + url);
|
||||
Log.d(LOG_TAG, "Download file:" + url);
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead = 0;
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead = 0;
|
||||
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
|
||||
// write bytes to file
|
||||
while ( (bytesRead = inputStream.read(buffer)) > 0 ) {
|
||||
// write bytes to file
|
||||
while ( (bytesRead = inputStream.read(buffer)) > 0 ) {
|
||||
outputStream.write(buffer,0, bytesRead);
|
||||
}
|
||||
|
||||
outputStream.close();
|
||||
|
||||
Log.d(LOG_TAG, "Saved file: " + target);
|
||||
|
||||
// create FileEntry object
|
||||
FileUtils fileUtil = new FileUtils();
|
||||
|
||||
return fileUtil.getEntry(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("Error: Unable to connect to domain");
|
||||
}
|
||||
|
||||
outputStream.close();
|
||||
|
||||
Log.d(LOG_TAG, "Saved file: " + target);
|
||||
|
||||
// create FileEntry object
|
||||
FileUtils fileUtil = new FileUtils();
|
||||
|
||||
return fileUtil.getEntry(file);
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, e.getMessage(), e);
|
||||
throw new IOException("Error while downloading");
|
||||
|
@ -141,5 +141,7 @@ public interface CordovaInterface {
|
||||
boolean clearHistory, HashMap<String, Object> params);
|
||||
|
||||
public abstract Context getApplicationContext();
|
||||
|
||||
public abstract boolean isUrlWhiteListed(String source);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user