Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## [Unreleased]

- Add scan scope selector: Project, Diff (between two revisions or the local directory) and File
- Increase required CLI version to 3.25.0
- Update extension icon to the new Cycode brand logo

## [3.1.1] - 2026-08-30
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The extension provides functionalities such as:
* Company’s Custom Remediation Guidelines - If your company has set custom remediation guidelines via the Cycode portal, you'll see a field for "Company Guidelines" that contains those guidelines.
* Running a new scan from your IDE even before committing the code.
* Triggering a scan automatically whenever a file is saved.
* Choosing the scan scope: the whole project, only the changes between two revisions (Diff), or the open file.
* Highlighting vulnerable code in the editor - syntax highlighting for Cycode-specific code and configuration files,
making it easy for users to identify and work with these files in their projects.
* Removing a detected secret or ignoring it by secret value, rule (type) or by path.
Expand Down Expand Up @@ -82,6 +83,24 @@ To use the Cycode IntelliJ Platform Plugin, follow these steps:
4. Also applies for auto-save.
5. Wait for the scan to complete and to display a success message.

### Scan Scope

In the Cycode tool window, choose what the scan buttons and **Scan all** run on:

* **Project** - scans the entire project.
* **Diff** - scans only what changed. Pick two revisions in **From** and **To** (HEAD, branches, tags or recent
commits), or choose **Local directory** on one side to include your uncommitted changes. The default is
Local directory compared with HEAD. Two different revisions are required.
* Scanning only the changes is faster, but vulnerabilities that need the surrounding code may be less accurate.
* Infrastructure As Code scans do not support diffs and always scan the full project.
* The project must be inside a Git repository (otherwise Diff is disabled). Diff needs Cycode CLI 3.25.0 or later:
with a custom CLI that is older, the plugin shows one notification asking you to upgrade it or to turn
automatic CLI management back on.
* **File** - scans only the file open in the editor. Package vulnerability and Infrastructure As Code scans only run
for the file types they support.

The scope is remembered for each project between sessions. The selected revisions are kept for the current session only.

## Viewing Scan Results

### Handling Detected Secrets
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rootProject.name = "Cycode plugin for IntelliJ Platform"

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0")
id("org.gradle.toolchains.foojay-resolver-convention") version("1.0.0")
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/cycode/plugin/Consts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Consts {
companion object {
val PLUGIN_PATH = PathManager.getPluginsPath() + "/cycode-intellij-platform-plugin"
val DEFAULT_CLI_PATH = getDefaultCliPath()
const val REQUIRED_CLI_VERSION = "3.21.0"
const val REQUIRED_CLI_VERSION = "3.25.0"

const val CYCODE_DOMAIN = "cycode.com"

Expand Down
42 changes: 42 additions & 0 deletions src/main/kotlin/com/cycode/plugin/cli/DiffScan.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.cycode.plugin.cli

enum class ScanScope {
Project, Diff, File
}

enum class DiffScanMode {
CommitRange, LocalDiff
}

/** Describes what a single CLI scan invocation should scan. */
sealed class ScanTarget {
data class Paths(val paths: List<String>) : ScanTarget()
data class Diff(val mode: DiffScanMode, val ref: String, val path: String) : ScanTarget()
}

fun ScanTarget.toCliArgs(): Array<String> = when (this) {
is ScanTarget.Paths -> arrayOf("path", *paths.toTypedArray())
is ScanTarget.Diff -> getDiffScanArgs(mode, ref, path)
}

// IaC is not supported by the CLI's commit-history and pre-commit diff flavours
fun supportsDiffScan(scanType: CliScanType): Boolean = scanType != CliScanType.Iac

fun getDiffScanArgs(mode: DiffScanMode, ref: String, path: String): Array<String> {
assertSafeRefArg(ref)

return when (mode) {
DiffScanMode.CommitRange -> arrayOf("commit-history", "--commit-range", ref, path)
DiffScanMode.LocalDiff -> arrayOf("pre-commit", "--include-unstaged", "--base-ref", ref, "--path", path)
}
}

/**
* Refs are passed to git and the CLI as separate arguments (no shell), but a value like "--output=x"
* would still be parsed as an option. Reject those and anything containing control characters.
*/
fun assertSafeRefArg(ref: String) {
require(isSafeRefArg(ref)) { "Unsafe revision: must be non-empty, not start with '-' and have no control characters" }
}

fun isSafeRefArg(ref: String): Boolean = ref.isNotEmpty() && !ref.startsWith("-") && ref.none { it.isISOControl() }
13 changes: 13 additions & 0 deletions src/main/kotlin/com/cycode/plugin/cli/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ fun isSupportedLockFile(filename: String): Boolean {
return false
}

fun isFileSupportedByScanType(filePath: String, scanType: CliScanType): Boolean {
return when (scanType) {
CliScanType.Sca -> isSupportedPackageFile(filePath)
CliScanType.Iac -> isSupportedIacFile(filePath)
else -> true
}
}

/** Splits [scanTypes] (keeping their order) into the ones that can scan the file and the ones that cannot. */
fun partitionByFileSupport(filePath: String, scanTypes: List<CliScanType>): Pair<List<CliScanType>, List<CliScanType>> {
return scanTypes.partition { isFileSupportedByScanType(filePath, it) }
}

fun getPackageFileForLockFile(filename: String): String {
val lowercaseFilename = filename.lowercase()
return SCA_CONFIGURATION_SCAN_LOCK_FILE_TO_PACKAGE_FILE.getOrDefault(lowercaseFilename, "package")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.cycode.plugin.components.toolWindow.components.cycodeActionToolBar.actions

import com.cycode.plugin.CycodeBundle
import com.cycode.plugin.cli.CliScanType
import com.cycode.plugin.services.cycode
import com.cycode.plugin.services.pluginLocalState
import com.cycode.plugin.services.scanScope
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
Expand All @@ -26,21 +25,7 @@ class RunAllAction :
// TODO(MarshalX): we should tracks all running scans and use pub-sub messaging to update UI
// we can provide "stop" action only after that
val project = e.project ?: return
val service = cycode(project)
val pluginLocalState = pluginLocalState(project)

if (pluginLocalState.isSecretScanningEnabled) {
service.startScanForCurrentProject(CliScanType.Secret)
}
if (pluginLocalState.isScaScanningEnabled) {
service.startScanForCurrentProject(CliScanType.Sca)
}
if (pluginLocalState.isIacScanningEnabled) {
service.startScanForCurrentProject(CliScanType.Iac)
}
if (pluginLocalState.isSastScanningEnabled) {
service.startScanForCurrentProject(CliScanType.Sast)
}
scanScope(project).startAllScansForCurrentScope()
}

override fun update(e: AnActionEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@ package com.cycode.plugin.components.toolWindow.components.scanContentTab

import com.cycode.plugin.CycodeBundle
import com.cycode.plugin.cli.CliScanType
import com.cycode.plugin.cli.ScanScope
import com.cycode.plugin.components.Component
import com.cycode.plugin.components.common.createClickableLabel
import com.cycode.plugin.components.toolWindow.updateToolWindowState
import com.cycode.plugin.git.HEAD_REF
import com.cycode.plugin.git.DiffSide
import com.cycode.plugin.git.RefOption
import com.cycode.plugin.services.CycodeService
import com.cycode.plugin.services.CycodeTemporaryStateService
import com.cycode.plugin.services.diffRefs
import com.cycode.plugin.services.pluginLocalState
import com.cycode.plugin.services.scanScope
import com.intellij.icons.AllIcons
import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.SimpleListCellRenderer
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBRadioButton
import com.intellij.util.ui.JBUI
import java.awt.FlowLayout
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import javax.swing.Box
import javax.swing.ButtonGroup
import javax.swing.DefaultComboBoxModel
import javax.swing.JButton
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.SwingConstants

class ScanContentTab : Component<CycodeService>() {
private val panel = JPanel(GridBagLayout())
Expand All @@ -21,6 +39,7 @@ class ScanContentTab : Component<CycodeService>() {
anchor = GridBagConstraints.NORTHWEST
fill = GridBagConstraints.HORIZONTAL
}
private var updatingCombos = false

private fun addComponentToPanel(component: JComponent) {
gbc.gridy++
Expand All @@ -32,34 +51,138 @@ class ScanContentTab : Component<CycodeService>() {
val pluginLocalState = pluginLocalState(service.project)

addComponentToPanel(createClickableLabel(CycodeBundle.message("scanTabTitleLabel")))
addComponentToPanel(
JButton(CycodeBundle.message("scanTabSecretsBtn")).apply {
isEnabled = pluginLocalState.isSecretScanningEnabled
addActionListener { service.startScanForCurrentProject(CliScanType.Secret) }
},
)
addComponentToPanel(
JButton(CycodeBundle.message("scanTabScaBtn")).apply {
isEnabled = pluginLocalState.isScaScanningEnabled
addActionListener { service.startScanForCurrentProject(CliScanType.Sca) }
},
)
addComponentToPanel(
JButton(CycodeBundle.message("scanTabIacBtn")).apply {
isEnabled = pluginLocalState.isIacScanningEnabled
addActionListener { service.startScanForCurrentProject(CliScanType.Iac) }
},
)
addComponentToPanel(
JButton(CycodeBundle.message("scanTabSastBtn")).apply {
isEnabled = pluginLocalState.isSastScanningEnabled
addActionListener { service.startScanForCurrentProject(CliScanType.Sast) }
},
)
addScopeControls(service)
CycodeTemporaryStateService.SCAN_TYPES_IN_ORDER.forEach { scanType ->
addComponentToPanel(createScanButton(service, scanType, pluginLocalState.isScanTypeEnabled(scanType)))
}

addComponentToPanel(createClickableLabel(CycodeBundle.message("scanTabOnSaveTip")))
addComponentToPanel(createClickableLabel(CycodeBundle.message("howToUseLabel")))

return panel
}

private fun createScanButton(service: CycodeService, scanType: CliScanType, enabled: Boolean): JButton {
val key = when (scanType) {
CliScanType.Secret -> "scanTabSecretsBtn"
CliScanType.Sca -> "scanTabScaBtn"
CliScanType.Iac -> "scanTabIacBtn"
CliScanType.Sast -> "scanTabSastBtn"
}
return JButton(CycodeBundle.message(key)).apply {
isEnabled = enabled
addActionListener { scanScope(service.project).startScanForCurrentScope(scanType) }
}
}

private fun createNote(text: String, icon: javax.swing.Icon? = null): JBLabel {
return JBLabel("<html>$text</html>").apply {
setAllowAutoWrapping(true)
icon?.let {
this.icon = it
iconTextGap = JBUI.scale(6)
verticalTextPosition = SwingConstants.TOP
}
}
}

private fun addScopeControls(service: CycodeService) {
val scopeService = scanScope(service.project)
val effectiveScope = scopeService.getEffectiveScanScope()
val diffRefs = diffRefs(service.project)
val isGitRepository = diffRefs.isGitRepository

// Diff is disabled when this turns out not to be a git repository; the tab is rebuilt if that changes
diffRefs.refreshGitRepositoryState()

addComponentToPanel(createClickableLabel(CycodeBundle.message("scanScopeLabel")))

val group = ButtonGroup()
val radioPanel = JPanel(FlowLayout(FlowLayout.LEFT, 0, 0))
ScanScope.entries.forEach { scope ->
val radio = JBRadioButton(CycodeBundle.message("scanScope${scope.name}"), scope == effectiveScope).apply {
// Diff cannot work without a git repository
isEnabled = scope != ScanScope.Diff || isGitRepository != false
addActionListener {
if (scope != scopeService.getScanScope()) {
scopeService.setScanScope(scope)
updateToolWindowState(service.project)
}
}
}
group.add(radio)
radioPanel.add(radio)
radioPanel.add(Box.createHorizontalStrut(JBUI.scale(12)))
}
addComponentToPanel(radioPanel)
addComponentToPanel(createNote(CycodeBundle.message("scanScope${effectiveScope.name}Hint")))
if (isGitRepository == false) {
addComponentToPanel(createNote(CycodeBundle.message("scanScopeDiffNoGitNote"), AllIcons.General.Warning))
}

if (effectiveScope != ScanScope.Diff) {
return
}

val fromCombo = createRefCombo(service, true)
val toCombo = createRefCombo(service, false)
addComponentToPanel(JPanel(GridBagLayout()).apply {
val c = GridBagConstraints().apply { fill = GridBagConstraints.HORIZONTAL; gridy = 0 }
add(JBLabel(CycodeBundle.message("scanScopeDiffFromLabel")), c.apply { gridx = 0; weightx = 0.0 })
add(fromCombo, c.apply { gridx = 1; weightx = 1.0; insets = JBUI.insets(0, 4, 0, 8) })
add(JBLabel(CycodeBundle.message("scanScopeDiffToLabel")), c.apply { gridx = 2; weightx = 0.0; insets = JBUI.emptyInsets() })
add(toCombo, c.apply { gridx = 3; weightx = 1.0; insets = JBUI.insetsLeft(4) })
})
addComponentToPanel(createNote(CycodeBundle.message("scanScopeDiffIacNote"), AllIcons.General.Warning))

// lists are reloaded in the background and the combos updated in place (never while a popup is open)
diffRefs.refresh {
populateCombo(fromCombo, true, diffRefs.from, diffRefs.refs)
populateCombo(toCombo, false, diffRefs.to, diffRefs.refs)
}
}

/** A combo entry: the local directory or a revision. */
private class SideOption(val side: DiffSide, val label: String) {
override fun toString() = label
}

private fun createRefCombo(service: CycodeService, isFrom: Boolean): ComboBox<SideOption> {
val diffRefs = diffRefs(service.project)
return ComboBox<SideOption>().apply {
// long labels are truncated instead of widening the tool window
setMinimumAndPreferredWidth(JBUI.scale(REF_COMBO_WIDTH))
maximumRowCount = REF_COMBO_VISIBLE_ROWS
renderer = SimpleListCellRenderer.create("") { it.label }
populateCombo(this, isFrom, if (isFrom) diffRefs.from else diffRefs.to, diffRefs.refs)
addActionListener {
if (updatingCombos) return@addActionListener
val selected = (selectedItem as? SideOption)?.side ?: return@addActionListener
if (isFrom) diffRefs.setSides(selected, diffRefs.to) else diffRefs.setSides(diffRefs.from, selected)
}
}
}

private fun populateCombo(combo: ComboBox<SideOption>, isFrom: Boolean, selected: DiffSide, known: List<RefOption>) {
// replacing the model closes an open popup
if (combo.isPopupVisible) return

val refs = known.ifEmpty { listOf(RefOption(HEAD_REF, HEAD_REF)) }
val items = listOf(SideOption(DiffSide.Local, CycodeBundle.message("scanScopeDiffLocalDirectory"))) +
refs.map { SideOption(DiffSide.Rev(it.value), it.label) }

updatingCombos = true
try {
combo.model = DefaultComboBoxModel(items.toTypedArray())
combo.selectedItem = items.firstOrNull { it.side == selected }
?: items.first { it.side == if (isFrom) DiffSide.Local else DiffSide.Rev(HEAD_REF) }
} finally {
updatingCombos = false
}
}

companion object {
private const val REF_COMBO_WIDTH = 110
private const val REF_COMBO_VISIBLE_ROWS = 12
}
}
Loading
Loading