Docs/Rules/Jenkins (J01-J30)

Jenkins Rules (J01-J30)

30 rules for Jenkinsfile (Declarative & Scripted). Deducts from the Security Score.

Credentials & Secrets (J01-J05)

IDSevPtsDescriptionFix
J01CRIT4Shell command with Groovy string interpolationChange sh "${var}" to sh '${var}' with withCredentials
J02CRIT4No withCredentials block for secret usageWrap secret usage in withCredentials([...]) { }
J03HIGH3Hardcoded credentials in JenkinsfileStore in Jenkins Credentials and use withCredentials
J04HIGH3Echo or println leaking secretsRemove echo/println containing credential variables
J05MED3writeFile with secret contentUse Jenkins credentials binding instead of file-based secrets

Sandbox & Code Execution (J06-J10)

IDSevPtsDescriptionFix
J06CRIT4Groovy sandbox bypass attemptRemove sandbox bypass constructs - use approved methods
J07HIGH3No timeout on pipeline or stagesAdd timeout(time: 30, unit: 'MINUTES') to options
J08MED3No build discarder for log rotationAdd buildDiscarder(logRotator(numToKeepStr: '10'))
J09HIGH3Pipeline replay not disabledAdd disableReplay() to pipeline options block
J10HIGH3Using agent any without restrictionReplace agent any with agent { label 'build-node' }

Shared Libraries & Dependencies (J11-J15)

IDSevPtsDescriptionFix
J11CRIT4Shared library loaded without version pinningPin to specific version: @Library('lib@v1.2.3')
J12MED3No input validation for pipeline parametersValidate and sanitize all params before shell use
J13MED2No post-build cleanupAdd cleanWs() in post { always { } } block
J14HIGH3Running on master/built-in nodeUse agent { label 'build-node' } instead
J15MED3No post-failure handlingAdd post { failure { notify } always { cleanup } }

Security Controls (J16-J20)

IDSevPtsDescriptionFix
J16CRIT4bat command with string interpolationUse bat with single quotes and withCredentials
J17HIGH3Docker agent using latest tagPin Docker agent image to specific version
J18MED3No input submitter restrictionAdd submitter: 'admin,deployers' to input step
J19MED2Archiving sensitive artifactsExclude sensitive files from archiveArtifacts
J20HIGH3Building fork PRs without restrictionDisable fork PR builds or use sandbox

Best Practices (J21-J25)

IDSevPtsDescriptionFix
J21MED3No retry on deployment stagesAdd retry(2) on deployment and external service stages
J22MED2No resource locking for deploymentsAdd lock(resource: 'deploy-prod') around deploy stage
J23LOW2No durability hint for pipeline performanceAdd durabilityHint('PERFORMANCE_OPTIMIZED') to options
J24MED2No parallel execution for independent stagesRun independent stages in parallel {} block
J25MED3No error handling with catchError or try-catchUse catchError or try-catch for non-critical stages

Advanced Security (J26-J30)

IDSevPtsDescriptionFix
J26HIGH4Using script block in declarative pipelineMinimize script blocks - use declarative steps
J27MED3No notification on pipeline status changeAdd slackSend or emailext in post { failure { } }
J28HIGH3Unstash or stash containing secretsNever stash sensitive files - use withCredentials per stage
J29MED2No when condition for stage executionAdd when { branch 'main' } conditions for deploy stages
J30MED3No JNLP agent security restrictionRestrict agent connections with security realm settings
Total: 30 rules across 6 sections. All deduct from the Security Score.