Skip to content

Commit a72d888

Browse files
committed
chore: Fix the security issue raised by running npm without a path.
1 parent 29e8268 commit a72d888

6 files changed

Lines changed: 48 additions & 17 deletions

File tree

examples/prisma/mysql/test/connect.cjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
const {execSync} = require('node:child_process');
15+
const {spawnSync} = require('node:child_process');
1616
const {resolve} = require('node:path');
1717
const t = require('tap');
1818

1919
function generatePrismaClient() {
2020
const schemaPath = resolve(__dirname, '../schema.prisma');
21+
const prismaPath = resolve(
22+
__dirname,
23+
'../../../../node_modules/.bin/prisma'
24+
);
2125

22-
execSync(`npm exec prisma -- generate --schema=${schemaPath}`);
26+
spawnSync(prismaPath, ['generate', `--schema=${schemaPath}`], {
27+
stdio: 'inherit',
28+
});
2329
}
2430

2531
t.test('mysql prisma cjs', async t => {

examples/prisma/mysql/test/connect.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { execSync } from 'node:child_process';
15+
import {spawnSync} from 'node:child_process';
1616
import { dirname, resolve } from 'node:path'
1717
import { fileURLToPath } from 'node:url'
1818
import t from 'tap';
1919

20+
const __dirname = dirname(fileURLToPath(import.meta.url));
21+
2022
function generatePrismaClient() {
21-
const p = fileURLToPath(import.meta.url)
22-
const __dirname = dirname(p)
2323
const schemaPath = resolve(__dirname, '../schema.prisma');
24+
const prismaPath = resolve(
25+
__dirname,
26+
'../../../../node_modules/.bin/prisma'
27+
);
2428

25-
execSync(`npm exec prisma -- generate --schema=${schemaPath}`);
29+
spawnSync(prismaPath, ['generate', `--schema=${schemaPath}`], {
30+
stdio: 'inherit',
31+
});
2632
}
2733

2834
t.test('mysql prisma mjs', async t => {

examples/prisma/mysql/test/connect.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {execSync} from 'node:child_process';
15+
import {spawnSync} from 'node:child_process';
1616
import {resolve} from 'node:path';
1717
import t from 'tap';
1818

1919
function generatePrismaClient() {
2020
const schemaPath = resolve(__dirname, '../schema.prisma');
21+
const prismaPath = resolve(__dirname, '../../../../node_modules/.bin/prisma');
2122

22-
execSync(`npm exec prisma -- generate --schema=${schemaPath}`);
23+
spawnSync(prismaPath, ['generate', `--schema=${schemaPath}`], {
24+
stdio: 'inherit',
25+
});
2326
}
2427

2528
t.test('mysql prisma ts', async t => {
2629
// prisma client generation should normally be part of a regular Prisma
2730
// setup on user end but in order to tests in many different databases
2831
// we run the generation step at runtime for each variation
29-
generatePrismaClient();
32+
await generatePrismaClient();
3033

3134
const {
3235
default: {connect},

examples/prisma/postgresql/test/connect.cjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
const {execSync} = require('node:child_process');
15+
const {spawnSync} = require('node:child_process');
1616
const {resolve} = require('node:path');
1717
const t = require('tap');
1818

1919
function generatePrismaClient() {
2020
const schemaPath = resolve(__dirname, '../schema.prisma');
21+
const prismaPath = resolve(
22+
__dirname,
23+
'../../../../node_modules/.bin/prisma'
24+
);
2125

22-
execSync(`npm exec prisma -- generate --schema=${schemaPath}`);
26+
spawnSync(prismaPath, ['generate', `--schema=${schemaPath}`], {
27+
stdio: 'inherit',
28+
});
2329
}
2430

31+
2532
t.test('pg prisma cjs', async t => {
2633
// prisma client generation should normally be part of a regular Prisma
2734
// setup on user end but in order to tests in many different databases

examples/prisma/postgresql/test/connect.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { execSync } from 'node:child_process';
15+
import { spawnSync} from 'node:child_process';
1616
import { dirname, resolve } from 'node:path'
1717
import { fileURLToPath } from 'node:url'
1818
import t from 'tap';
1919

20+
const __dirname = dirname(fileURLToPath(import.meta.url));
21+
2022
function generatePrismaClient() {
21-
const p = fileURLToPath(import.meta.url)
22-
const __dirname = dirname(p)
2323
const schemaPath = resolve(__dirname, '../schema.prisma');
24+
const prismaPath = resolve(
25+
__dirname,
26+
'../../../../node_modules/.bin/prisma'
27+
);
2428

25-
execSync(`npm exec prisma -- generate --schema=${schemaPath}`);
29+
spawnSync(prismaPath, ['generate', `--schema=${schemaPath}`], {
30+
stdio: 'inherit',
31+
});
2632
}
2733

2834
t.test('pg prisma mjs', async t => {

examples/prisma/postgresql/test/connect.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {execSync} from 'node:child_process';
15+
import {spawnSync} from 'node:child_process';
1616
import {resolve} from 'node:path';
1717
import t from 'tap';
1818

1919
function generatePrismaClient() {
2020
const schemaPath = resolve(__dirname, '../schema.prisma');
21+
const prismaPath = resolve(__dirname, '../../../../node_modules/.bin/prisma');
2122

22-
execSync(`npm exec prisma -- generate --schema=${schemaPath}`);
23+
spawnSync(prismaPath, ['generate', `--schema=${schemaPath}`], {
24+
stdio: 'inherit',
25+
});
2326
}
2427

2528
t.test('pg prisma ts', async t => {

0 commit comments

Comments
 (0)