7.8 KiB
Security Quick Reference Guide
Access Control
User Roles and Permissions
| Role | Model | Read | Write | Create | Delete |
|---|---|---|---|---|---|
| Survey Manager | Wizard | ✓ | ✓ | ✓ | ✓ |
| Survey Manager | Placeholder | ✓ | ✓ | ✓ | ✓ |
| Survey Manager | Survey (custom fields) | ✓ | ✓ | ✓ | ✓ |
| Survey User | Wizard | ✓ (own) | ✗ | ✗ | ✗ |
| Survey User | Placeholder | ✓ (own) | ✗ | ✗ | ✗ |
| Survey User | Survey (has_custom_certificate) | ✓ | ✗ | ✗ | ✗ |
Field-Level Security
| Field | Visible To | Editable By |
|---|---|---|
| custom_cert_template | Survey Manager | Survey Manager |
| custom_cert_template_filename | Survey Manager | Survey Manager |
| custom_cert_mappings | Survey Manager | Survey Manager |
| has_custom_certificate | Survey User+ | Survey Manager |
Input Validation Rules
Placeholder Keys
Format: {key.field_name}
Rules:
- Must start with
{key. - Must end with
} - Field name can only contain: letters, numbers, underscores
- Maximum length: 200 characters
Valid Examples:
{key.name}{key.course_name}{key.field_123}
Invalid Examples:
key.name(missing braces){key.field-name}(hyphen not allowed){key.field name}(space not allowed)
Value Fields
Rules:
- Can only contain: letters, numbers, underscores, dots
- Maximum length: 200 characters
- No special characters or spaces
Valid Examples:
survey_titlepartner_id.namepartner_id.email
Invalid Examples:
field-name(hyphen not allowed)field name(space not allowed)field'; DROP TABLE--(SQL injection attempt)
Custom Text
Rules:
- Maximum length: 1000 characters
- HTML tags are escaped/removed
- Control characters are removed
- Special characters are sanitized
Sanitization Applied:
- HTML escaping (< becomes <, etc.)
- Control character removal
- HTML tag stripping
- Length truncation if needed
JSON Mappings Structure
Required Structure
{
"placeholders": [
{
"key": "{key.field_name}",
"value_type": "survey_field|user_field|custom_text",
"value_field": "field_name",
"custom_text": "text"
}
]
}
Validation Rules
- Must be valid JSON syntax
- Root must be a dictionary/object
- Must contain "placeholders" key
- "placeholders" must be a list/array
- Each placeholder must be a dictionary
- Each placeholder must have "key" and "value_type"
- "key" must match placeholder key format
- "value_type" must be one of: survey_field, user_field, custom_text
- "value_field" maximum 200 characters
- "custom_text" maximum 1000 characters
Security Features
Protection Against Attacks
| Attack Type | Protection Method |
|---|---|
| XSS (Cross-Site Scripting) | HTML escaping, tag stripping |
| SQL Injection | Field name validation, character whitelisting |
| Command Injection | Input sanitization, pattern validation |
| Path Traversal | Field name validation, no path separators |
| DoS (Denial of Service) | File size limits, text length limits |
| Data Corruption | JSON validation, database constraints |
Sanitization Methods
_sanitize_placeholder_value(value)
Purpose: Sanitize user input for safe use in documents
Actions:
- HTML escape all characters
- Remove control characters (except \n and \t)
- Strip HTML tags
- Truncate to 10,000 characters
Usage:
safe_value = wizard._sanitize_placeholder_value(user_input)
_sanitize_certificate_value(value)
Purpose: Sanitize data before certificate generation
Actions: Same as _sanitize_placeholder_value
Usage:
safe_value = survey._sanitize_certificate_value(data_value)
Validation Methods
_validate_placeholder_key(key)
Purpose: Validate placeholder key format
Returns: Boolean (True if valid)
Usage:
if wizard._validate_placeholder_key(key):
# Key is valid
_validate_json_structure(json_string)
Purpose: Validate JSON mappings structure
Returns: Tuple (is_valid, error_message)
Usage:
is_valid, error = wizard._validate_json_structure(json_str)
if not is_valid:
raise ValidationError(error)
_validate_and_sanitize_placeholders()
Purpose: Validate all placeholders before saving
Raises: ValidationError if validation fails
Usage:
wizard._validate_and_sanitize_placeholders()
Database Constraints
Placeholder Model Constraints
- source_key: Format and length validation
- value_field: Character whitelist and length validation
- custom_text: Length validation
Survey Model Constraints
- custom_cert_mappings: JSON structure validation
Security Best Practices
For Developers
- Always sanitize user input before using in documents
- Validate at multiple layers: UI, application, database
- Use whitelisting instead of blacklisting for validation
- Log security events for audit trails
- Fail securely with clear error messages
For Administrators
- Restrict access to survey managers only
- Monitor logs for suspicious activity
- Keep Odoo updated for security patches
- Review templates before deployment
- Test with malicious inputs before production
For Users
- Use strong passwords for survey manager accounts
- Don't share credentials with unauthorized users
- Report suspicious activity to administrators
- Review generated certificates for unexpected content
- Keep templates simple to reduce attack surface
Common Security Errors
Error: "Invalid placeholder key format"
Cause: Placeholder key doesn't match required pattern
Solution: Use format {key.field_name} with only letters, numbers, underscores
Error: "Invalid characters in field name"
Cause: value_field contains special characters
Solution: Use only letters, numbers, underscores, and dots
Error: "Custom text too long"
Cause: Custom text exceeds 1000 characters
Solution: Reduce text length or split into multiple placeholders
Error: "Invalid JSON in certificate mappings"
Cause: Malformed JSON structure
Solution: Check JSON syntax and required structure
Testing Security
Manual Security Tests
-
Test with XSS payloads:
<script>alert('XSS')</script><img src=x onerror=alert('XSS')>
-
Test with SQL injection:
field'; DROP TABLE users--1' OR '1'='1
-
Test with path traversal:
../../etc/passwd..\..\..\windows\system32
-
Test with long inputs:
- 1001+ character custom text
- 201+ character field names
-
Test with malformed JSON:
- Missing braces
- Invalid structure
- Wrong data types
Automated Security Tests
Run the security test suite:
odoo-bin -c odoo.conf -d database_name -i survey_custom_certificate_template --test-enable --stop-after-init
Or run specific test:
odoo-bin -c odoo.conf -d database_name --test-tags survey_custom_certificate_template.test_security_validation
Security Checklist
Before deploying to production:
- All users have appropriate access levels
- Field-level security is configured
- Input validation is working
- Sanitization is applied to all user inputs
- JSON validation is enforced
- Database constraints are active
- Security tests pass
- Logs are monitored
- File size limits are enforced
- Error messages don't leak sensitive information
Support
For security issues or questions:
- Check this guide first
- Review the implementation documentation
- Run security tests
- Contact system administrator
- Report security vulnerabilities privately
Version
Document Version: 1.0 Last Updated: 2024 Module Version: 19.0.1.0.0