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

chore: print a warning when the user uses paths outside CWD #3313

Merged
merged 1 commit into from
Jun 13, 2022
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
26 changes: 26 additions & 0 deletions src/cli/commands/test/iac/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { UnsupportedEntitlementError } from '../../../../lib/errors/unsupported-
import * as ora from 'ora';
import { CustomError, FormattedCustomError } from '../../../../lib/errors';
import { scan } from './scan';
import * as path from 'path';

const debug = Debug('snyk-test');
const SEPARATOR = '\n-------------------------------------------------------\n';
Expand Down Expand Up @@ -74,6 +75,10 @@ export default async function(
if (shouldLogUserMessages(options, isNewIacOutputSupported)) {
console.log(EOL + iacTestTitle + EOL);

if (paths.some(isOutsideCurrentWorkingDirectory)) {
teodora-sandu marked this conversation as resolved.
Show resolved Hide resolved
printCurrentWorkingDirectoryTraversalWarning();
}

testSpinner = ora({ isSilent: options.quiet, stream: process.stdout });
}

Expand Down Expand Up @@ -317,3 +322,24 @@ export default async function(
stringifiedSarifData,
);
}

function isOutsideCurrentWorkingDirectory(p: string): boolean {
return path.relative(process.cwd(), p).includes('..');
}

function printCurrentWorkingDirectoryTraversalWarning() {
let msg = '';

msg +=
'Warning: Scanning paths outside the current working directory is deprecated and' +
EOL;
msg +=
'will be removed in the future. Please see the documentation for further details:' +
EOL +
EOL;
msg +=
' https://docs.snyk.io/products/snyk-infrastructure-as-code/snyk-cli-for-infrastructure-as-code/test-your-configuration-files' +
EOL;

console.log(chalk.yellow(msg));
}