Skip to content
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

fix(dev-env): CWE-367 in getConfigurationFileOptions() #1652

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/lib/dev-environment/dev-environment-configuration-file.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import chalk from 'chalk';
import debugLib from 'debug';
import { constants } from 'fs';
import yaml, { FAILSAFE_SCHEMA } from 'js-yaml';
import { access, readFile } from 'node:fs/promises';
import { readFile } from 'node:fs/promises';
import path from 'node:path';

import * as exit from '../cli/exit';
Expand All @@ -17,15 +16,15 @@ export async function getConfigurationFileOptions(): Promise< ConfigurationFileO
const configurationFilePath = path.join( process.cwd(), CONFIGURATION_FILE_NAME );
let configurationFileContents = '';

const fileExists = await access( configurationFilePath, constants.R_OK )
.then( () => true )
.catch( () => false );

if ( fileExists ) {
debug( 'Reading configuration file from:', configurationFilePath );
try {
configurationFileContents = await readFile( configurationFilePath, 'utf8' );
} else {
return {};
debug( 'Read configuration file from %s', configurationFilePath );
} catch ( err ) {
if ( ( err as NodeJS.ErrnoException ).code === 'ENOENT' ) {
return {};
}

throw err;
}

let configurationFromFile: Record< string, unknown > = {};
Expand Down
Loading