From c1204816db2917336b7b0af2d640d78b5cf0ab9a Mon Sep 17 00:00:00 2001 From: captain6541 <386407904@qq.com> Date: Sun, 9 Oct 2022 14:32:47 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=E3=80=91fix-cross-path-attack-risk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/eclipsesource/v8/NodeJS.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eclipsesource/v8/NodeJS.java b/src/main/java/com/eclipsesource/v8/NodeJS.java index 30d148364..328f8f7b1 100644 --- a/src/main/java/com/eclipsesource/v8/NodeJS.java +++ b/src/main/java/com/eclipsesource/v8/NodeJS.java @@ -98,7 +98,7 @@ public void invoke(final V8Object receiver, final V8Array parameters) { try { File startupScript = createTemporaryScriptFile(STARTUP_SCRIPT, STARTUP_SCRIPT_NAME); try { - v8.createNodeRuntime(startupScript.getAbsolutePath()); + v8.createNodeRuntime(startupScript.getCanonicalPath()); } finally { startupScript.delete(); } @@ -165,9 +165,11 @@ public V8Object require(final File file) { v8.checkThread(); V8Array requireParams = new V8Array(v8); try { - requireParams.push(file.getAbsolutePath()); + requireParams.push(file.getCanonicalPath()); return (V8Object) require.call(null, requireParams); - } finally { + } catch (IOException e) { + throw new RuntimeException(e); + }finally { requireParams.close(); } } @@ -202,8 +204,10 @@ private V8Function createScriptExecutionCallback(final File file) { public Object invoke(final V8Object receiver, final V8Array parameters) { V8Array requireParams = new V8Array(v8); try { - requireParams.push(file.getAbsolutePath()); + requireParams.push(file.getCanonicalPath()); return require.call(null, requireParams); + } catch (IOException e) { + throw new RuntimeException(e); } finally { requireParams.close(); }