11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst fs = require('fs').promises; 51cb0ef41Sopenharmony_ciconst { MessageChannel } = require('worker_threads'); 61cb0ef41Sopenharmony_ciconst { once } = require('events'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Test that overriding the internal kTransfer method of a JSTransferable does 91cb0ef41Sopenharmony_ci// not enable loading arbitrary code from internal Node.js core modules. 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci(async function() { 121cb0ef41Sopenharmony_ci const fh = await fs.open(__filename); 131cb0ef41Sopenharmony_ci assert.strictEqual(fh.constructor.name, 'FileHandle'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci const kTransfer = Object.getOwnPropertySymbols(Object.getPrototypeOf(fh)) 161cb0ef41Sopenharmony_ci .filter((symbol) => symbol.description === 'messaging_transfer_symbol')[0]; 171cb0ef41Sopenharmony_ci assert.strictEqual(typeof kTransfer, 'symbol'); 181cb0ef41Sopenharmony_ci fh[kTransfer] = () => { 191cb0ef41Sopenharmony_ci return { 201cb0ef41Sopenharmony_ci data: '✨', 211cb0ef41Sopenharmony_ci deserializeInfo: 'net:Socket' 221cb0ef41Sopenharmony_ci }; 231cb0ef41Sopenharmony_ci }; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci const { port1, port2 } = new MessageChannel(); 261cb0ef41Sopenharmony_ci port1.postMessage(fh, [ fh ]); 271cb0ef41Sopenharmony_ci port2.on('message', common.mustNotCall()); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci const [ exception ] = await once(port2, 'messageerror'); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci assert.strictEqual(exception.message, 'Unknown deserialize spec net:Socket'); 321cb0ef41Sopenharmony_ci port2.close(); 331cb0ef41Sopenharmony_ci})().then(common.mustCall()); 34