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

token validation feature in ide #496

Merged
merged 10 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jfrog-vscode-extension",
"displayName": "JFrog",
"description": "Security scanning for your Go, npm, Pypi, Maven and NuGet projects.",
"version": "2.11.7",
"version": "2.11.6",
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved
"license": "Apache-2.0",
"icon": "resources/extensionIcon.png",
"repository": {
Expand Down Expand Up @@ -332,7 +332,7 @@
"dependencies": {
"adm-zip": "~0.5.9",
"fs-extra": "~10.1.0",
"jfrog-client-js": "^2.8.0",
"jfrog-client-js": "^2.9.0",
"jfrog-ide-webview": "https://releases.jfrog.io/artifactory/ide-webview-npm/jfrog-ide-webview/-/jfrog-ide-webview-0.2.14.tgz",
"js-yaml": "^4.1.0",
"json2csv": "~5.0.7",
Expand Down
2 changes: 1 addition & 1 deletion src/main/connect/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ export class ConnectionManager implements ExtensionComponent, vscode.Disposable
.xray()
.jasconfig()
.getJasConfig();
this._logManager.logMessage('Successfully got token validation from platform', 'DEBUG');
this._logManager.logMessage('Got token validation value:' + response.enable_token_validation_scanning +' from platform', 'DEBUG');
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved
return response.enable_token_validation_scanning;
} catch (error) {
this._logManager.logMessage('Failed getting token validation from platform', 'DEBUG');
Expand Down
7 changes: 7 additions & 0 deletions src/main/scanLogic/scanManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export class ScanManager implements ExtensionComponent {
if (scanDetails.multiScanId) {
params = { msi: scanDetails.multiScanId };
}
if (scanDetails.jasRunnerFactory.supportedScans.tokenValidation) {
if (params) {
params.tokenValidation = scanDetails.jasRunnerFactory.supportedScans.tokenValidation
} else {
params = {tokenValidation: scanDetails.jasRunnerFactory.supportedScans.tokenValidation}
}
}
for (const runner of jasRunners) {
if (runner.shouldRun()) {
scansPromises.push(
Expand Down
35 changes: 5 additions & 30 deletions src/main/scanLogic/scanRunners/analyzerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { Configuration } from '../../utils/configuration';
import { Translators } from '../../utils/translators';
import { BinaryEnvParams } from './jasRunner';
import { LogUtils } from '../../log/logUtils';
import { DYNAMIC_TOKEN_VALIDATION_MIN_XRAY_VERSION } from './secretsScan';
import * as semver from 'semver';

/**
* Analyzer manager is responsible for running the analyzer on the workspace.
Expand Down Expand Up @@ -151,34 +149,8 @@ export class AnalyzerManager {
};
}

private isTokenValidationEnabled(): string {
let xraySemver: semver.SemVer = new semver.SemVer(this._connectionManager.xrayVersion);
if (xraySemver.compare(DYNAMIC_TOKEN_VALIDATION_MIN_XRAY_VERSION) < 0) {
this._logManager.logMessage(
'You cannot use dynamic token validation feature on xray version ' +
this._connectionManager.xrayVersion +
' as it requires xray version ' +
DYNAMIC_TOKEN_VALIDATION_MIN_XRAY_VERSION,
'INFO'
);
return 'false';
}
if (Configuration.enableTokenValidation()) {
return 'true';
}
let response: Promise<boolean> = this._connectionManager.isTokenValidationPlatformEnabled();
let tokenValidation: boolean = false;
response.then(res => {
tokenValidation = res;
});
if (tokenValidation || process.env.JF_VALIDATE_SECRETS) {
return 'true';
}

return 'false';
}

private populateOptionalInformation(binaryVars: NodeJS.ProcessEnv, params?: BinaryEnvParams) {
private async populateOptionalInformation(binaryVars: NodeJS.ProcessEnv, params?: BinaryEnvParams) {
// Optional proxy information - environment variable
let proxyHttpUrl: string | undefined = process.env['HTTP_PROXY'];
let proxyHttpsUrl: string | undefined = process.env['HTTPS_PROXY'];
Expand All @@ -190,7 +162,10 @@ export class AnalyzerManager {
proxyHttpUrl = 'http://' + proxyUrl;
proxyHttpsUrl = 'https://' + proxyUrl;
}
binaryVars[AnalyzerManager.JF_VALIDATE_SECRETS] = this.isTokenValidationEnabled();

if (params?.tokenValidation && params.tokenValidation == true) {
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved
binaryVars[AnalyzerManager.JF_VALIDATE_SECRETS] = "true"
}
if (proxyHttpUrl) {
binaryVars[AnalyzerManager.ENV_HTTP_PROXY] = this.addOptionalProxyAuthInformation(proxyHttpUrl);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/scanLogic/scanRunners/analyzerModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export interface FileRegion {
startColumn: number;
endColumn: number;
snippet?: ResultContent;
tokenValidation?: string;
metadata?: string;
properties: { [key: string]: string };
}

export interface ResultContent {
Expand Down
1 change: 1 addition & 0 deletions src/main/scanLogic/scanRunners/jasRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface RunRequest {
export interface BinaryEnvParams {
executionLogDirectory?: string;
msi?: string;
tokenValidation?: boolean;
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/main/scanLogic/sourceCodeScan/supportedScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ import { ConnectionManager } from '../../connect/connectionManager';
import { ConnectionUtils, EntitlementScanFeature } from '../../connect/connectionUtils';
import { LogManager } from '../../log/logManager';
import { ScanUtils } from '../../utils/scanUtils';
import * as semver from 'semver';
import { DYNAMIC_TOKEN_VALIDATION_MIN_XRAY_VERSION } from '../scanRunners/secretsScan';
import { Configuration } from '../../utils/configuration';

export class SupportedScans {
private _applicability?: boolean;
private _sast?: boolean;
private _iac?: boolean;
private _secrets?: boolean;
private _tokenValidation?: boolean;
constructor(private _connectionManager: ConnectionManager, protected _logManager: LogManager) {}

get tokenValidation(): boolean | undefined {
return this._tokenValidation
}

public setTokenValidation(value: boolean| undefined): SupportedScans {
this._tokenValidation = value;
return this;
}

get applicability(): boolean | undefined {
return this._applicability;
}
Expand Down Expand Up @@ -72,6 +85,11 @@ export class SupportedScans {
.then(res => this.setSast(res))
.catch(err => ScanUtils.onScanError(err, this._logManager, true))
);
requests.push(
this.isTokenValidationEnabled()
.then(res => this.setTokenValidation(res))
.catch(err => ScanUtils.onScanError(err, this._logManager, true))
);
await Promise.all(requests);
return this;
}
Expand Down Expand Up @@ -102,4 +120,30 @@ export class SupportedScans {
public async isSastSupported(): Promise<boolean> {
return await ConnectionUtils.testXrayEntitlementForFeature(this._connectionManager.createJfrogClient(), EntitlementScanFeature.Sast);
}

/**
* Check if token validation scan is enabled
*/
public async isTokenValidationEnabled(): Promise<boolean> {
let xraySemver: semver.SemVer = new semver.SemVer(this._connectionManager.xrayVersion);
if (xraySemver.compare(DYNAMIC_TOKEN_VALIDATION_MIN_XRAY_VERSION) < 0) {
this._logManager.logMessage(
'You cannot use dynamic token validation feature on xray version ' +
this._connectionManager.xrayVersion +
' as it requires xray version ' +
DYNAMIC_TOKEN_VALIDATION_MIN_XRAY_VERSION,
'INFO'
);
return false;
}
if (Configuration.enableTokenValidation()) {
return true;
}
let tokenValidation: boolean = await this._connectionManager.isTokenValidationPlatformEnabled();
if (tokenValidation || process.env.JF_VALIDATE_SECRETS) {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class SecretTreeNode extends CodeIssueTreeNode {
issue.severity,
issue.ruleName
);
this._tokenValidation = location.tokenValidation;
this._metadata = location.metadata;
this._tokenValidation = location.properties?.tokenValidation;
this._metadata = location.properties?.metadata;
this._snippet = location.snippet?.text;
this._fullDescription = issue.fullDescription;
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/treeDataProviders/utils/analyzerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ export class AnalyzerUtils {
);
let fileIssue: SecurityIssue = AnalyzerUtils.getOrCreateSecurityIssue(fileWithIssues, analyzeIssue, fullDescription);
let newLocation: FileRegion = location.physicalLocation.region;
newLocation.tokenValidation = analyzeIssue.properties?.tokenValidation
? (analyzeIssue.properties.tokenValidation.trim() as keyof typeof TokenStatus)
: '';
newLocation.metadata = analyzeIssue.properties?.metadata ? analyzeIssue.properties.metadata.trim() : '';
let properties: {[key: string]: string} = {
"tokenValidation": analyzeIssue.properties?.tokenValidation
? (analyzeIssue.properties.tokenValidation.trim() as keyof typeof TokenStatus) : '',
"metadata": analyzeIssue.properties?.metadata ? analyzeIssue.properties.metadata.trim() : ''
}
newLocation.properties = properties
fileIssue.locations.push(newLocation);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/tests/utils/testAnalyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export function assertTokenValidationResult(
let fileNode: CodeFileTreeNode = getTestCodeFileNode(testRoot, expectedFileIssues.full_path);
expectedFileIssues.issues.forEach((expectedIssues: SecurityIssue) => {
expectedIssues.locations.forEach((expectedLocation: FileRegion) => {
assert.deepEqual(getTestIssueNode(fileNode, expectedLocation).metadata, expectedLocation.metadata);
assert.deepEqual(getTestIssueNode(fileNode, expectedLocation).tokenValidation, expectedLocation.tokenValidation);
assert.deepEqual(getTestIssueNode(fileNode, expectedLocation).metadata, expectedLocation.properties?.metadata);
assert.deepEqual(getTestIssueNode(fileNode, expectedLocation).tokenValidation, expectedLocation.properties?.tokenValidation);
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/test/tests/utils/testIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,17 @@ export function assertIssuesTokenValidationExist(
responseFilesWithIssues,
expectedIssues.ruleId,
expectedLocation
).tokenValidation,
expectedLocation.tokenValidation
).properties?.tokenValidation,
expectedLocation.properties?.tokenValidation
);
assert.deepEqual(
getTestLocation(
path.join(testDataRoot, expectedFileWithIssues.full_path),
responseFilesWithIssues,
expectedIssues.ruleId,
expectedLocation
).metadata,
expectedLocation.metadata
).properties?.metadata,
expectedLocation.properties?.metadata
);
});
});
Expand Down
Loading