Check access validation 63/203563/10
authorDongHyun Song <dh81.song@samsung.com>
Tue, 16 Apr 2019 02:34:46 +0000 (11:34 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Thu, 18 Apr 2019 01:56:33 +0000 (10:56 +0900)
This is for checking vailiation of file access,
All webapp only can be allowed predefined path list

Change-Id: I0a7156a04c40a115c72b7806ee843b5b3d6b66b6

wrt_app/src/web_application.js

index 863774e..c81a263 100755 (executable)
@@ -16,7 +16,7 @@
 
 'use strict';
 
-const {BrowserWindow, app} = require('electron');
+const {BrowserWindow, app, protocol} = require('electron');
 const WAS_EVENT = require('./was_event');
 const wrt = require('../browser/wrt');
 
@@ -43,6 +43,33 @@ class WebApplication {
         } else {
             this.preloadState = 'none';
         }
+        this.accessiblePath = wrt.getAccessiblePath();
+        console.log(this.accessiblePath);
+        if (this.accessiblePath) {
+            protocol.interceptFileProtocol('file', (request, callback) => {
+                const url = require('url');
+                let access_path, parsed_info = url.parse(request.url);
+                access_path = parsed_info.host + parsed_info.pathname;
+                console.log("check path: " + access_path);
+
+                for (let p in this.accessiblePath) {
+                    if (access_path.startsWith(this.accessiblePath[p])) {
+                        callback(access_path);
+                        return;
+                    }
+                }
+                if (access_path.indexOf("/shared/res/") > -1) {
+                    callback(access_path);
+                    return;
+                }
+                else {
+                    console.log("invalid access: " + access_path);
+                    callback(403);
+                }
+            }, (error) => {
+                console.log(error);
+            });
+        }
     }
     getBrowserWindowOption(options) {
         return {