Location Research Breakthrough Possible @S-Logix pro@slogix.in

Local Outlier Factor-Based Detection and Mitigation of Malicious Command Injection in Jenkins Jenkinsfile Build Steps Using Automated Script Behavior Analysis

Description

Jenkins is an open-source automation server used to automate software building, testing, and deployment through Continuous Integration and Continuous Delivery (CI/CD) pipelines. A Jenkins pipeline defines a sequence of operations, such as checking out source code, installing dependencies, executing build commands, running security tests, and preparing application artifacts.

The Jenkinsfile defines the pipeline configuration and its build stages. If an attacker modifies a Jenkinsfile or introduces an unauthorized command into a build stage, the pipeline may execute suspicious operations within the permissions and environment available to the Jenkins agent.

Malicious build-step injection may involve unexpected shell commands, unauthorized script downloads, suspicious command chaining, or attempts to access sensitive files and environment variables. Such behaviour can compromise build integrity, expose credentials, or affect the security of generated software artifacts.

In this use case, Jenkins is deployed on an Ubuntu virtual machine in an isolated VirtualBox laboratory. Controlled pipeline configurations are maintained in a Git repository, and harmless normal and suspicious build-step examples are prepared for testing. A publicly available cybersecurity dataset containing relevant command or script-behaviour records is also used for model development and evaluation. The selected dataset must provide features that can be mapped meaningfully to the behavioural features extracted from Jenkins build steps.

Python is used to process the public dataset, extract relevant features, and prepare structured data for analysis. The Local Outlier Factor (LOF) algorithm analyses the local density of feature vectors and identifies build steps that differ significantly from their surrounding behavioural patterns. Dataset preprocessing and feature compatibility checks are performed before the model is applied to Jenkins pipeline data.

The public dataset supports model development and evaluation, while controlled Jenkins pipeline test cases are used to assess the detection workflow in the target environment. Dataset records are not assumed to represent Jenkins-specific attacks automatically; only relevant records and compatible features are used. The limitations of applying dataset-derived patterns to Jenkins build steps are documented.

The proposed system does not assume that every unusual command is malicious. LOF generates anomaly scores, and the detected build steps are reviewed against security rules and the expected pipeline configuration before a security decision is made.

Semgrep CE provides supplementary static analysis for supported source code and security patterns. Gitleaks checks the repository for potential hardcoded secrets, while Trivy examines supported container images and configuration files for known vulnerabilities and security misconfigurations. These tools complement the primary AI-based detection mechanism rather than replacing it.

Docker is used where required to isolate controlled build execution. A Python-based Streamlit dashboard presents detected anomalies, affected pipeline stages, relevant indicators, security findings, and assessment results.

When a suspicious build step is confirmed, Jenkins pipeline controls are used to prevent the affected build from proceeding. The build configuration is reviewed, the unauthorized command is removed or corrected, and the pipeline is executed again to validate the remediation.

The complete security-validation workflow is:
Public Cybersecurity Dataset Collection
→
Dataset Inspection
→
Data Preprocessing
→
Feature Engineering
→
Dataset-Based LOF Model Development
→
Jenkinsfile Collection
→
Build-Step Feature Extraction
→
Anomaly Detection
→
Security Rule Validation
→
Risk Assessment
→
Build Execution Control
→
Script Remediation
→
Post-Remediation Validation

Existing Security Problem

Application/Service: Jenkins CI/CD Pipeline

Jenkins is the target CI/CD automation service in this use case.

It executes pipeline stages defined in a Jenkinsfile and coordinates build, testing, and other automation tasks through configured agents.

Existing Problem :

Jenkins pipelines execute commands according to their configuration and the permissions available to the executing agent. If unauthorized or malicious commands are introduced into a build stage, they may execute as part of an otherwise legitimate pipeline.

Traditional pipeline execution does not automatically determine whether every command represents unusual or potentially malicious behaviour. Basic syntax validation and successful build completion cannot independently establish that a pipeline is secure.

Static analysis and secret scanning can identify certain security weaknesses, but they do not independently detect every malicious build-step behaviour. An additional behaviour-analysis mechanism is required to identify unusual patterns that warrant investigation.

Public cybersecurity datasets can provide records for developing and evaluating anomaly-detection techniques. However, the selected dataset must contain relevant behavioural information, and its features must be compatible with the features extracted from Jenkins build steps. Otherwise, its records cannot directly support reliable Jenkins-specific detection.

The security problem is:
Jenkins CI/CD Pipeline
→
Jenkinsfile Configuration
→
Build-Step Command Execution
→
Unauthorized or Malicious Command Injection
→
Unexpected Build-Step Behaviour
→
Potential Credential Exposure or Build Integrity Impact
→
Need for Dataset-Supported Anomaly Detection and Mitigation

The proposed solution introduces public dataset collection, dataset preprocessing, compatible feature extraction, LOF-based anomaly detection, security-rule validation, risk prioritization, controlled build execution, and post-remediation validation.

Attack

Specific Attack: Malicious Build-Step Injection Attack

The controlled attack scenario evaluates whether an unauthorized or suspicious command introduced into a Jenkins pipeline can be identified before the affected build is allowed to proceed.

A controlled test Jenkinsfile contains normal build steps alongside harmless test cases representing suspicious command patterns. These may include unexpected external-download indicators, unusual command chaining, or attempts to reference sensitive environment variables.

The public cybersecurity dataset is used to support model development and evaluation. Controlled test cases are separately created in the laboratory to assess whether the resulting detection workflow identifies suspicious Jenkins build-step behaviour.

The laboratory uses inert test commands and dummy credentials. No real credentials are accessed, no malicious payload is executed, and no unauthorized external system is targeted.

Attack Behavior :
Controlled Jenkins Pipeline
→
Jenkinsfile Build-Step Modification
→
Suspicious Command Pattern Introduced
→
Automated Build-Script Analysis
→
Build-Step Feature Extraction
→
LOF Anomaly Detection
→
Security Rule Validation
→
Suspicious Build-Step Flagged
→
Build Execution Restricted
→
Pipeline Configuration Remediation
→
Post-Remediation Validation

Security Concept

AI-Based Anomaly Detection Combined with Secure CI/CD Pipeline Execution Controls

The primary security concept is AI-based anomaly detection combined with secure CI/CD pipeline execution controls.

A publicly available cybersecurity dataset is collected and inspected to identify records relevant to command or script behaviour. The selected records are preprocessed, and appropriate features are extracted and transformed into a structured representation. Dataset features are checked for compatibility with the features that can be extracted from Jenkins build steps.

The Local Outlier Factor algorithm analyses the local density of the prepared feature vectors and identifies samples that differ from their local neighbourhood. Since LOF is an unsupervised anomaly-detection algorithm, it does not require labelled classes for model fitting. Where suitable labels are available, they can support independent evaluation of the model's detection performance.

The model is evaluated using appropriate dataset samples and separate controlled Jenkins build-step test cases. Results from these two evaluation settings are reported separately so that performance on the public dataset is not incorrectly presented as proven performance against Jenkins-specific attacks.

The system extracts measurable features from pipeline commands and their associated metadata. Static security checks, repository comparisons, and predefined security rules provide additional evidence for validating alerts. An anomaly score alone is not treated as proof of malicious activity.

Gitleaks checks for potential hardcoded secrets, Semgrep CE identifies supported security patterns, and Trivy checks supported container images and configurations. These findings contribute to the overall security assessment but are not treated as proof that a build step is malicious.

The assessment follows:
Public Cybersecurity Dataset Collection
→
Dataset Inspection and Relevance Assessment
→
Data Cleaning and Preprocessing
→
Feature Selection and Engineering
→
Feature Compatibility Validation
→
LOF Model Preparation and Fitting
→
Dataset-Based Model Evaluation
→
Jenkinsfile Collection and Parsing
→
Build-Step Feature Extraction
→
Jenkins Build-Step Anomaly Detection
→
Security Rule Validation
→
Finding Validation and Risk Assessment
→
Build Execution Restriction
→
Jenkinsfile Remediation
→
Post-Remediation Security Validation

Defensive Mechanism

Public Dataset Preparation

A publicly available cybersecurity dataset containing relevant command or script-behaviour records is inspected before use. Only records and fields suitable for the intended analysis are selected.

Purpose
  • Establish a relevant data source for model development and evaluation.

Dataset Preprocessing

Python is used to clean the selected dataset, handle missing or inconsistent values, remove duplicate records where appropriate, and prepare the data for feature extraction.

Purpose
  • Prepare consistent and usable data for anomaly detection.

Feature Engineering and Compatibility Validation

Relevant behavioural features are extracted from the dataset and Jenkins build steps. The feature representation is checked to ensure that the model receives compatible inputs during development, testing, and deployment.

Purpose
  • Ensure that dataset-derived and Jenkins-derived features can be meaningfully compared.

Local Outlier Factor Anomaly Detection

The LOF model compares the local density of feature vectors and assigns anomaly scores to samples that differ from their local neighbourhood.

Purpose
  • Identify unusual behavioural patterns that require security investigation.

Jenkinsfile Change Review

Pipeline configuration changes are reviewed against the approved Git version to identify unexpected modifications to build stages and commands.

Purpose
  • Identify unauthorized changes to Jenkins pipeline build steps before execution.

Build-Script Feature Extraction

Python parses supported pipeline scripts and extracts features such as command categories, shell operators, command-chain characteristics, external-download indicators, and references to environment variables.

Purpose
  • Convert build-script characteristics into structured input for automated anomaly detection.

Static Security Analysis

Semgrep CE scans supported source code and security patterns using configured rules. Its ability to analyse individual Jenkins pipeline constructs depends on the language and rules supported by the selected version.

Purpose
  • Identify supported security weaknesses and suspicious code patterns that supplement AI-based anomaly detection.

Secret Detection

Gitleaks scans the project repository and relevant tracked files for potential hardcoded secrets.

Purpose
  • Identify potential credential exposure in source files and repository history.

Vulnerability and Configuration Scanning

Trivy scans supported container images, filesystems, and configuration files for known vulnerabilities and security misconfigurations.

Purpose
  • Identify supplementary vulnerabilities and configuration weaknesses that may affect the build environment.

Security Rule Validation

Detected anomalies are checked against predefined security rules, approved command patterns, and the intended pipeline configuration.

Purpose
  • Reduce false positives and distinguish unusual but legitimate build operations from confirmed security violations.

Controlled Build Execution

Suspicious builds are prevented from proceeding until the required review or approval is completed.

Purpose
  • Prevent unvalidated build steps from executing in the controlled pipeline.

Jenkins Agent Permission Restriction

Build agents are configured with only the permissions required for their assigned tasks, and sensitive credentials are not exposed unnecessarily to pipeline commands.

Purpose
  • Limit the potential impact of a compromised or malicious build step.

Build Environment Isolation

Controlled build jobs are executed in an appropriately isolated environment, using Docker where suitable and available.

Purpose
  • Reduce unintended interaction between suspicious build operations and other laboratory services.

Risk-Based Prioritization

Findings are prioritized according to the suspicious behaviour, available permissions, possible credential exposure, and potential impact on build integrity.

Purpose
  • Establish the appropriate remediation priority for each validated finding.

Build-Script Remediation

Confirmed unauthorized commands are removed or corrected, and the resulting pipeline configuration is reviewed before execution is permitted again.

Purpose
  • Remove the identified malicious build step and restore the approved pipeline configuration.

Post-Remediation Validation

The updated pipeline is analysed again, and controlled tests verify that the suspicious build step is no longer present and the expected build operations remain functional.

Purpose
  • Confirm that the remediation is effective without unnecessarily disrupting legitimate build operations.

Security Tools

Primary CI/CD Automation Tool: Jenkins

Jenkins is the primary platform because it executes the pipeline stages defined in the Jenkinsfile and supports controlled build validation.

Purpose
  • Create and execute controlled CI/CD pipelines.
  • Run normal and suspicious build-step test cases.
  • Integrate security checks into pipeline stages.
  • Stop builds when required security validations fail.
  • Validate pipeline behaviour after remediation.

Public Dataset Source: Public Cybersecurity Dataset

A publicly available cybersecurity dataset is used as the data source for model development and evaluation. The selected dataset must contain relevant behavioural records, and its features must be suitable for mapping to the intended anomaly-detection workflow.

Purpose
  • Obtain publicly available cybersecurity records for analysis.
  • Select relevant records and features.
  • Support model development and independent evaluation.
  • Assess the limitations of applying dataset-derived patterns to Jenkins build steps.

Dataset Processing Tool: Python Pandas and NumPy

Pandas and NumPy are used to inspect, clean, transform, and prepare the selected dataset for feature analysis.

Purpose
  • Load and inspect dataset records.
  • Handle missing or inconsistent data.
  • Prepare structured feature data.
  • Support data transformation and feature engineering.
  • Produce consistent inputs for model development.

AI Anomaly Detection Tool: Python scikit-learn

Python scikit-learn provides the Local Outlier Factor implementation used to analyse structured dataset and build-step features.

Purpose
  • Prepare feature vectors for build-step analysis.
  • Configure and execute the LOF algorithm.
  • Calculate anomaly scores for evaluated samples.
  • Identify unusual feature patterns.
  • Evaluate detection performance using suitable test samples.

Build-Script Analysis Tool: Python

Python is used to parse supported pipeline scripts, extract measurable command characteristics, apply security checks, and coordinate the detection workflow.

Purpose
  • Read and process controlled Jenkinsfile samples.
  • Extract command and pipeline metadata features.
  • Prepare input data for LOF analysis.
  • Correlate anomaly results with security rules.
  • Generate structured detection findings.

Static Application Security Testing Tool: Semgrep CE

Semgrep CE is an open-source static analysis tool used to identify supported security issues in source code and scripts.

Purpose
  • Scan supported project files using security rules.
  • Identify code patterns associated with supported security weaknesses.
  • Supplement the primary AI-based detection findings.
  • Provide additional evidence for security review.

Secret Detection Tool: Gitleaks

Gitleaks is an open-source tool used to identify potential secrets exposed in source files and Git repositories.

Purpose
  • Scan the project repository for hardcoded secrets.
  • Identify potential credential exposure in tracked files.
  • Detect accidental inclusion of test credentials or sensitive strings.
  • Support remediation of repository-level secret exposure.

Vulnerability and Misconfiguration Scanning Tool: Trivy

Trivy is an open-source security scanner that supports container images, filesystems, and several configuration formats.

Purpose
  • Scan container images for known vulnerabilities.
  • Check supported configuration files for security misconfigurations.
  • Identify supplementary security findings in the build environment.
  • Provide additional evidence for risk assessment.

Network Security Assessment Tool: Nmap

Nmap is an open-source network discovery and security auditing tool used for authorized assessment of the laboratory network.

Purpose
  • Identify exposed services within the authorized laboratory.
  • Verify that only intended network services are reachable.
  • Support validation of the laboratory's network boundaries.

Source-Control Tool: Git

Git maintains version history for pipeline configurations and allows the current Jenkinsfile to be compared with an approved version.

Purpose
  • Store approved pipeline configurations.
  • Track changes to build scripts.
  • Compare modified scripts with trusted versions.
  • Identify unexpected build-step changes.
  • Support rollback to an approved configuration.

Build Isolation Tool: Docker Engine

Docker provides container-based isolation for controlled build operations when compatible with the Jenkins agent configuration.

Purpose
  • Run controlled build workloads in containers.
  • Separate supported build tasks from the host environment.
  • Support repeatable testing conditions.
  • Reduce unnecessary interaction with other laboratory services.
  • Assist in controlled post-remediation testing.

Security Dashboard Tool: Streamlit

Streamlit provides a Python-based interface for displaying anomaly detection results and security assessment evidence.

Purpose
  • Display detected build-step anomalies.
  • Show affected pipeline stages and extracted indicators.
  • Present anomaly scores and security-rule results.
  • Display supplementary findings from integrated security tools.
  • Show assessment and remediation status.

Target Operating System: Ubuntu Linux

Ubuntu provides the primary laboratory environment for Jenkins, Python, Git, and the associated analysis components.

Purpose
  • Host the Jenkins service and required dependencies.
  • Maintain the controlled source-code repository.
  • Run the Python analysis workflow.
  • Apply and validate pipeline security controls.
  • Collect implementation and testing evidence.

Security Testing Platform: Kali Linux

Kali Linux provides a separate security-testing environment for controlled assessment activities where required.

Purpose
  • Support authorized security testing.
  • Assist in reviewing accessible laboratory services.
  • Validate the intended network boundaries.
  • Support controlled verification of the secured environment.

Virtualization Platform: VirtualBox

VirtualBox provides the isolated virtual-machine infrastructure for the laboratory.

Purpose
  • Host the Ubuntu laboratory virtual machine.
  • Host the Kali Linux testing virtual machine.
  • Establish controlled virtual networking.
  • Separate the laboratory from production infrastructure.

Process

STEP 01

Prepare the Isolated CI/CD Security Environment

  • Create an isolated cybersecurity laboratory using VirtualBox.
  • Configure Ubuntu as the primary Jenkins server
  • Configure Kali Linux as the separate security-testing system.
  • Establish controlled network communication between the virtual machines.
  • Verify that the laboratory services are reachable only as intended.
  • Confirm that the assessment is restricted to the authorized laboratory.
  • Record the initial laboratory configuration.
Tools: VirtualBox + Ubuntu + Kali Linux
STEP 02

Deploy Jenkins CI/CD

  • Install Jenkins on the Ubuntu laboratory server.
  • Start the Jenkins service and complete its initial configuration.
  • Configure an authorized administrator account.
  • Verify that the Jenkins web interface is accessible.
  • Configure a suitable build agent or controlled local execution environment.
  • Verify that Jenkins can execute a harmless test job.
  • Record the initial Jenkins configuration.
Tools: Jenkins + Ubuntu
STEP 03

Prepare the Source-Controlled Pipeline

  • Create a Git repository for the laboratory project.
  • Create a Jenkinsfile containing normal build stages.
  • Include harmless operations such as source validation and test execution.
  • Commit the approved pipeline configuration to Git.
  • Record the trusted version of the Jenkinsfile.
  • Verify that the pipeline executes its expected build stages.
  • Preserve the approved configuration as the baseline.
Tools: Git + Jenkins
STEP 04

Collect and Inspect the Public Cybersecurity Dataset

  • Identify a publicly available cybersecurity dataset containing relevant command or script-behaviour records.
  • Review the dataset's documentation, data format, available fields, and intended use.
  • Inspect the available records to determine whether they contain behavioural information relevant to the intended anomaly-detection objective.
  • Identify the features that can be mapped meaningfully to the features extracted from Jenkins build steps.
  • Check whether the dataset contains duplicate records, missing values, inconsistent formats, or irrelevant fields.
  • Determine whether the available records are suitable for model development and evaluation.
  • Do not assume that a general cybersecurity dataset automatically represents Jenkins-specific command injection attacks.
  • Document the dataset's relevance, limitations, and suitability for the proposed use case.
Tools: Python + Pandas + NumPy
STEP 05

Preprocess the Dataset and Prepare the Features

  • Load the selected public dataset into the Python analysis environment.
  • Inspect the data types, feature distributions, missing values, and inconsistent records.
  • Clean the data and handle missing or invalid values using suitable preprocessing methods.
  • Remove irrelevant fields that do not contribute to the intended analysis.
  • Select behavioural features that can be represented consistently in the model.
  • Transform the selected features into a structured numerical representation suitable for LOF.
  • Apply appropriate feature scaling where required.
  • Check that the prepared dataset contains usable feature vectors.
  • Document the preprocessing decisions and any limitations affecting the resulting data.
Tools: Python + Pandas + NumPy + scikit-learn
STEP 06

Prepare Jenkins Build-Step Samples and Validate Feature Compatibility

  • Create a Git repository for the laboratory project if it has not already been prepared.
  • Create a Jenkinsfile containing normal build stages.
  • Run the approved pipeline under controlled conditions.
  • Collect relevant build-step commands and pipeline metadata.
  • Prepare separate test copies of the approved Jenkinsfile.
  • Introduce harmless test patterns representing suspicious command behaviour, such as unexpected external-download indicators, unusual command chaining, and references to sensitive environment variables.
  • Ensure that test cases do not access real credentials or execute malicious payloads.
  • Extract behavioural features from the Jenkins build steps using Python.
  • Compare the Jenkins-derived features with the selected dataset features.
  • Confirm that both data sources can be represented using the same meaningful feature definitions before applying the model across them.
  • If the selected public dataset does not provide compatible features, do not directly combine its feature vectors with Jenkins feature vectors. Document the limitation and restrict the dataset to the tasks it can validly support.
Tools: Jenkins + Git + Python + Pandas + NumPy
STEP 07

Perform Feature Engineering and Prepare the Model Input

  • Convert the selected dataset records into structured feature records.
  • Extract the compatible behavioural features required for the intended anomaly detection objective.
  • Prepare corresponding feature records from the controlled Jenkins build-step samples.
  • Ensure that feature names, meanings, data types, and ordering remain consistent wherever the same model is applied.
  • Avoid storing real secrets or unnecessary sensitive values in the feature records.
  • Apply the same required preprocessing and feature-scaling procedures to training
  • and evaluation data.
  • Verify that the resulting feature vectors can be processed by the selected LOF implementation.
  • Keep the public dataset records and controlled Jenkins test samples identifiable as separate data sources for evaluation.
Tools: Python + Pandas + NumPy + scikit-learn
STEP 08

Prepare the LOF Anomaly Detection Model

  • Load the prepared dataset-derived feature vectors into the Python analysis environment.
  • Select numerical features relevant to the intended detection objective.
  • Apply consistent preprocessing and feature scaling where required.
  • Configure the Local Outlier Factor algorithm.
  • Select suitable neighbourhood parameters and the expected contamination setting based on the experimental design.
  • Determine whether the model is being used for outlier analysis on a dataset or novelty detection on previously unseen samples.
  • Configure the appropriate LOF mode for the intended use.
  • Record the selected parameters and model configuration.
  • Verify that the feature representation used during model preparation is compatible with the intended evaluation data.
Tools: Python + scikit-learn
STEP 09

Fit and Evaluate the LOF Model Using the Prepared Dataset

  • Fit the configured LOF model using the prepared dataset-derived feature vectors according to the selected model configuration.
  • Keep the evaluation samples separate from the samples used for model fitting where the experimental design requires independent evaluation.
  • Generate anomaly scores and predicted anomaly labels for the evaluated samples.
  • Where suitable labels are available, compare predictions with the corresponding known labels.
  • Calculate appropriate evaluation metrics, such as precision, recall, and F1-score, when the test labels and evaluation design support them.
  • Record false positives, false negatives, and other relevant observations.
  • Evaluate the model's performance on the selected public dataset without treating those results as proof of Jenkins-specific detection performance.
  • Document the model's parameters, evaluation procedure, and limitations.
Tools: Python + Pandas + NumPy + scikit-learn
STEP 10

Integrate Build-Step Analysis with Jenkins

  • Configure a controlled pipeline stage for the Python security-analysis script.
  • Pass the approved pipeline configuration to the analysis component.
  • Extract the features required by the LOF model.
  • Verify that the Jenkins-derived features match the model's expected input representation.
  • Generate anomaly scores for the evaluated build steps.
  • Run configured Semgrep CE and Gitleaks checks on the relevant project files.
  • Return the analysis results to the pipeline as structured output.
  • Configure the pipeline to stop when a defined security-validation condition fails.
Tools: Jenkins + Python + scikit-learn + Semgrep CE + Gitleaks
STEP 11

Execute the Controlled Build-Step Detection Assessment

  • Submit the approved baseline pipeline for analysis.
  • Submit the separate controlled suspicious test cases for analysis.
  • Collect the model's anomaly scores and predicted labels.
  • Identify the pipeline stages associated with the flagged samples.
  • Compare the detected patterns with the original approved configuration.
  • Review whether the extracted Jenkins features are compatible with the features used by the model.
  • Record the pipeline execution status and detection evidence.
  • Compare results with the expected behaviour of the controlled test cases.
  • Keep model predictions separate from confirmed security findings.
Tools: Jenkins + Python + scikit-learn + Git
STEP 12

Validate Detected Anomalies Against Security Rules

  • Review each build step flagged by the LOF model.
  • Compare the affected commands with the approved pipeline configuration.
  • Check for unexpected command patterns and suspicious configuration changes.
  • Apply predefined security rules to the available indicators.
  • Use Gitleaks findings to investigate potential hardcoded secrets.
  • Use Semgrep CE findings as supplementary evidence where the relevant rules support the files being analysed.
  • Determine whether the detected behaviour is expected or requires further investigation.
  • Record false positives and unresolved findings.
Tools: Python + Git + Jenkins + Gitleaks + Semgrep CE
STEP 13

Assess the Risk of Validated Findings

  • Review the validated suspicious build-step findings.
  • Identify the affected pipeline stage and command.
  • Determine the permissions available to the affected build agent.
  • Assess potential exposure of credentials and sensitive environment variables.
  • Use Trivy to review relevant container-image vulnerabilities and supported configuration weaknesses.
  • Consider the possible impact on build integrity and generated artifacts.
  • Assign a risk level using the documented assessment criteria.
  • Record the evidence supporting each risk assessment.
Tools: Python + Jenkins + Git + Trivy + Gitleaks
STEP 14

Configure Build Execution Restrictions

  • Define the conditions that require a build to stop or wait for review.
  • Configure Jenkins to fail the security-validation stage when a required check fails.
  • Prevent flagged test cases from progressing to subsequent build stages.
  • Configure suitable permissions for pipeline administrators and build agents.
  • Ensure that anomaly scores alone are not treated as proof of malicious intent.
  • Require the defined validation or approval procedure before a restricted build resumes.
  • Verify the expected pipeline behaviour using controlled test cases.
Tools: Jenkins + Python + Git
STEP 15

Remediate the Identified Build-Script Weakness

  • Review the affected Jenkinsfile and the associated security finding.
  • Compare the current configuration with the approved Git version.
  • Remove or correct the confirmed unauthorized build step.
  • Restore the intended pipeline command and stage configuration.
  • Review the updated configuration before committing the change.
  • Commit the approved remediation to the repository.
  • Record the remediation details for subsequent validation.
Tools: Git + Jenkins
STEP 16

Perform Post-Remediation Build-Step Testing

  • Collect the updated Jenkinsfile for analysis.
  • Repeat the feature-extraction procedure.
  • Run the updated build steps through the security-analysis stage.
  • Verify that the confirmed unauthorized command has been removed or corrected.
  • Compare the updated configuration with the approved baseline.
  • Run the relevant configured static-analysis and secret-detection checks again.
  • Preserve the post-remediation test evidence.
Tools: Jenkins + Python + scikit-learn + Git + Semgrep CE + Gitleaks
STEP 17

Validate Legitimate Build Operations

  • Execute the approved pipeline with its intended build steps.
  • Verify that expected build and testing stages complete successfully.
  • Confirm that legitimate commands are not unnecessarily blocked.
  • Review any anomalies associated with approved build operations.
  • Check whether model parameters or security rules require justified adjustments.
  • Verify that the configured execution restrictions remain effective.
  • Record the final legitimate-build validation results.
Tools: Jenkins + Python + scikit-learn + Git + Trivy
STEP 18

Perform Final Security Validation and Review

  • Review the initial and final pipeline configurations.
  • Compare the original and post-remediation detection results.
  • Review the LOF model's detection performance on the prepared public dataset evaluation samples.
  • Separately review the model's behaviour on the controlled Jenkins build-step test cases.
  • Calculate appropriate evaluation metrics, including precision, recall, and F1-score, where the test labels support them.
  • Review false positives, false negatives, and remaining detection limitations.
  • Verify that build restrictions and remediation controls work as intended.
  • Confirm that legitimate build operations remain functional.
  • Document the dataset source type, preprocessing decisions, feature compatibility checks, evaluation procedure, and actual test results without specifying the dataset name in the use-case document.
  • Document the limitations of applying public dataset-derived patterns to Jenkins-specific build-step behaviour.
  • Preserve the relevant test evidence and implementation results.
  • Finalize the Jenkins CI/CD build-step security assessment.
Tools: Jenkins + Python + Pandas + NumPy + scikit-learn + Git + Semgrep CE + Gitleaks + Trivy + Streamlit

Outcome

A Jenkins CI/CD pipeline is configured in an isolated Ubuntu laboratory, providing a controlled environment for evaluating malicious build-step detection.

A publicly available cybersecurity dataset containing relevant behavioural records is inspected and prepared for model development and evaluation. Dataset suitability and feature compatibility are assessed before its records are used by the anomaly-detection workflow.

The dataset preprocessing workflow uses Python, Pandas, and NumPy to clean and transform the selected records into structured feature data suitable for the intended analysis.

Feature engineering establishes a consistent representation for the relevant dataset records and Jenkins build-step samples. The compatibility checks help prevent unrelated or incompatible features from being incorrectly treated as equivalent inputs.

The Local Outlier Factor model analyses the prepared feature vectors and identifies unusual patterns based on local density. Its anomaly scores and predicted labels support further investigation rather than automatically confirming malicious activity.

Model performance is evaluated using appropriate dataset samples and, separately, controlled Jenkins build-step test cases. Where suitable test labels are available, evaluation metrics are calculated and the actual results are documented.

Detected anomalies are correlated with approved pipeline configurations and predefined security rules. Semgrep CE and Gitleaks provide supplementary static-analysis and secret-detection findings to support the security assessment.

Jenkins build execution controls are integrated with the security-validation workflow, allowing builds that fail required security checks to be stopped or held for review before proceeding.

The identified unauthorized build-step changes are corrected, and the updated Jenkinsfile is reviewed against the approved configuration to restore the intended pipeline behaviour.

Post-remediation testing verifies whether the suspicious build steps have been removed or corrected, while legitimate build operations are checked to ensure that the security controls do not unnecessarily disrupt the pipeline.

The complete Jenkins CI/CD build-step security workflow including public dataset preparation, feature engineering, LOF anomaly detection, cybersecurity scanning, security-rule validation, risk assessment, build execution control, remediation, dashboard reporting, and post-remediation evaluation is demonstrated in the controlled laboratory.