-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trusted フラグの追加 #249
trusted フラグの追加 #249
Conversation
@@ -1,4 +1,3 @@ | |||
export * from "./Runner"; | |||
export * from "./Platform"; | |||
export * from "./Looper"; | |||
export * from "./utilsInSandbox"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
headless-driver 側で定義しているグローバルオブジェクトの型定義を headless-driver-runner 側で定義しているのがどうにも奇妙で部分的な変更が困難だったため、 headless-driver 側からファイルロード関数を渡すように修正してしまいました。
@@ -34,7 +34,7 @@ beforeAll(() => { | |||
jest.spyOn(ExecuteVmScriptV3, "getFilePath").mockReturnValue(path.resolve(__dirname, "../../lib/", "ExecuteVmScriptV3.js")); | |||
}); | |||
|
|||
describe("ホスティングされたコンテンツの動作テスト", () => { | |||
describe("untrusted コンテンツの動作テスト (URL)", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このあたりは文言修正のみです。
describe("trusted コンテンツの動作テスト: 異常系", () => { | ||
// テストが上手く行かない (`NodeVM` 上で `process.exit()` が実行できてしまう) ため一旦無効に。 | ||
// TODO: テストが動作するように修正 | ||
xit("Akashic V1 のコンテンツで process が参照できないことを確認", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本来 NodeVM 上で process.exit()
を実行してもエラーとなる (process is not defined
となる) はずなのですが、どうにも process.exit()
が実行できてしまうようでした。
ミニマムのサンプルを作ってみても再現できず原因が全くわからないため、やむを得ず TODO コメントでテストコードのみ残しています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
調査してみたところ、どうやら context: host
とすると NodeVM の require 先では process.exit()
が有効となることがわかりました。これは仕様上の制限かもしれない (外部モジュールまで sandbox の制限をすると正常な動作が期待できないなどの理由) ため、そうであればこのテスト自体は不要となるかもしれません。
// module1.js
module.exports = () => {
require("./module2")();
}
// module2.js
module.exports = () => {
console.log('typeof process.exit', typeof process.exit);
}
// index.js
const { NodeVM } = require('vm2');
const vm1 = new NodeVM({
require: {
context: 'sandbox',
external: true,
}
});
const vm2 = new NodeVM({
require: {
context: 'host',
external: true,
}
});
// sandbox-0
vm1.run(`console.log('typeof process.exit', typeof process.exit)`);
// sandbox-1
vm1.run(`require('./module1')();`, 'index.js');
// sandbox-2
vm1.run(`require('./module2')();`, 'index.js');
// host-0
vm2.run(`console.log('typeof process.exit', typeof process.exit)`);
// host-1
vm2.run(`require('./module1')();`, 'index.js');
// host-2
vm2.run(`require('./module2')();`, 'index.js');
$ node index.js
typeof process.exit undefined
typeof process.exit undefined
typeof process.exit undefined
typeof process.exit undefined
typeof process.exit function
typeof process.exit function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/patriksimek/vm2#nodevm
require.context - host (default) to require modules in host and proxy them to sandbox. sandbox to load, compile and require modules in sandbox. Builtin modules except events always required in host and proxied to sandbox.
runner.stop(); | ||
}); | ||
|
||
it("Akashic V1 コンテンツで allowedUrls に指定していない外部アセットは読み込めないことを確認", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trusted でも allowUrls
が有効であることを確認します。
3: ExecVmScriptV3.getFilePath() | ||
const nvm = this.createVm(params.trusted); | ||
|
||
const runnerParameter: RunnerParameters = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
バージョンごとに runnerParameters
が異なることを想定して別々でパラメータを定義していましたが、型定義自体は RunnerParameters
であることには変わりないため共通の変数でまとめてしまいました。
}) | ||
.catch((e) => loader._onAssetError(this, e)); | ||
this.loadFileHandler(this.path, (err, text) => { | ||
// NOTE: v1 のため型については精査しない |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントが v1
となっています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おお、ありがとうございます。ややこしいので 過去バージョンのため〜〜
に統一してしまいました。
@@ -327,37 +298,46 @@ export class RunnerManager { | |||
} | |||
|
|||
protected async resolveContent(contentUrl: string): Promise<EngineConfiguration> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここと resolveGameConfiguration()
, loadJSON()
の async
も消せそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここは単に不要な return await
を嫌っただけなので他の箇所については修正する必要は無いかなと。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、理解しました。ありがとうございます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメント加えましたが approved.
* asset へのアクセスを許可する URL。 | ||
* この URL と一致もしくは先頭一致しない asset へのアクセスはエラーとなる。 | ||
* null が指定された場合は全てのアクセスを許可する。 | ||
* 信頼されたコンテンツであるかどうか。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
の場合と false
の場合の違いについてコメントしておきたいです。(特に true の場合に何が可能になるのか、どういう時に使用すべきでないか)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらコメント追加しました。
prepare-1.7.0 ブランチを master から派生してそちらにマージしようと思います。 |
このPullRequestが解決する内容
RunnerManager#createRunner()
のパラメータにtrusted
フラグを追加します。loadFile()
の処理を headless-driver 側に移動します。loadFileHandler()
) を渡すようにします。破壊的変更