diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt index c6cf9205ea..e02a32e278 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt @@ -31,6 +31,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.Ama import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererUnknownLanguage import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage +import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhispererTelemetryService import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.CODE_SCAN_CREATE_PAYLOAD_TIMEOUT_IN_SECONDS import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.CodeAnalysisScope import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.DEFAULT_CODE_SCAN_TIMEOUT_IN_SECONDS @@ -195,6 +196,9 @@ class CodeScanSessionConfig( files.forEach { file -> try { val relativePath = "${project.name}/${file.relativeTo(projectRoot.toNioPath())}" + if (relativePath.contains("../") || relativePath.contains("..\\")) { + CodeWhispererTelemetryService.getInstance().sendInvalidZipEvent(file, projectRoot.toNioPath(), relativePath) + } LOG.debug { "Selected file for truncation: $file" } it.putNextEntry(relativePath.toString(), file) } catch (e: Exception) { diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt index 5509fa07f0..59d82c3b44 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt @@ -51,9 +51,11 @@ import software.aws.toolkits.telemetry.Component import software.aws.toolkits.telemetry.CredentialSourceId import software.aws.toolkits.telemetry.MetricResult import software.aws.toolkits.telemetry.Result +import java.nio.file.Path import java.time.Duration import java.time.Instant import java.util.Queue +import kotlin.io.path.pathString @Service class CodeWhispererTelemetryService { @@ -609,6 +611,14 @@ class CodeWhispererTelemetryService { assert(ApplicationManager.getApplication().isUnitTestMode) return this.previousUserTriggerDecisions } + + fun sendInvalidZipEvent(filePath: Path, projectRoot: Path, relativePath: String) { + CodewhispererTelemetry.invalidZip( + filePath = filePath.pathString, + workspaceRoot = projectRoot.pathString, + relativePath = relativePath + ) + } } fun isTelemetryEnabled(): Boolean = AwsSettings.getInstance().isTelemetryEnabled diff --git a/plugins/core/jetbrains-community/resources/telemetryOverride.json b/plugins/core/jetbrains-community/resources/telemetryOverride.json index 3acc0cdce1..39e9d4ba31 100644 --- a/plugins/core/jetbrains-community/resources/telemetryOverride.json +++ b/plugins/core/jetbrains-community/resources/telemetryOverride.json @@ -177,6 +177,21 @@ "reloaded" ], "description": "Toolkit run state." + }, + { + "name": "filePath", + "type": "string", + "description": "The path of the file" + }, + { + "name": "workspaceRoot", + "type": "string", + "description": "The path of the project root" + }, + { + "name": "relativePath", + "type": "string", + "description": "The relative path of the file" } ], "metrics": [ @@ -530,6 +545,24 @@ } ], "passive": true + }, + { + "name": "codewhisperer_invalidZip", + "description": "Invalid zip file", + "metadata": [ + { + "type": "filePath", + "required": true + }, + { + "type": "workspaceRoot", + "required": true + }, + { + "type": "relativePath", + "required": true + } + ] } ] }