Skip to content

Security: Tanner-Davison/cpp-primer

Security

SECURITY.md

Security Policy

πŸ›‘οΈ Supported Versions

This project is a learning-focused C++ repository that prioritizes educational value and code safety. We maintain security best practices while ensuring examples remain accessible to learners.

πŸ”’ Security Focus Areas

  • Code Safety: Preventing undefined behavior and memory issues
  • Input Validation: Safe handling of user input in examples
  • Educational Security: Teaching secure coding practices
  • Responsible Disclosure: Proper handling of security concerns

🚨 Reporting a Vulnerability

πŸ“§ How to Report

If you discover a security vulnerability in this project, please report it responsibly:

  1. DO NOT create a public GitHub issue for security vulnerabilities
  2. DO email security concerns to: [[email protected]]
  3. DO include detailed information about the vulnerability
  4. DO allow time for investigation and response

πŸ“‹ What to Include in Your Report

  • Description: Clear explanation of the security issue
  • Location: Specific file(s) and line numbers affected
  • Impact: How the vulnerability could be exploited
  • Reproduction: Steps to reproduce the issue
  • Suggested Fix: If you have a solution in mind
  • Educational Context: How this affects learning objectives

⏱️ Response Timeline

  • Initial Response: Within 48 hours
  • Investigation: 1-2 weeks for thorough analysis
  • Fix Implementation: 1-4 weeks depending on complexity
  • Public Disclosure: After fix is implemented and tested

πŸ” Security Categories

πŸ”΄ Critical Security Issues

Memory Safety Vulnerabilities

  • Buffer overflows in examples
  • Use-after-free scenarios
  • Memory leaks that could be exploited
  • Uninitialized variable usage

Input Validation Issues

  • Unsafe string handling
  • Integer overflow vulnerabilities
  • Format string vulnerabilities
  • Path traversal in file operations

Educational Security Concerns

  • Examples that teach unsafe practices
  • Code that could be misused maliciously
  • Missing bounds checking in educational examples

🟑 Medium Priority Issues

Code Quality Security

  • Potential undefined behavior
  • Unsafe type conversions
  • Missing error handling
  • Inconsistent exception safety

Documentation Security

  • Missing security warnings in comments
  • Incomplete error handling documentation
  • Lack of input validation guidance

🟒 Low Priority Issues

Style and Best Practices

  • Code style that could lead to security issues
  • Missing const correctness
  • Inconsistent error handling patterns

πŸ› οΈ Security Best Practices

βœ… What We Encourage

Memory Safety

// βœ… Good: RAII and smart pointers
auto data = std::make_unique<std::vector<int>>();
std::vector<std::string> safe_strings;

// βœ… Good: Bounds checking
if (index < container.size()) {
    auto value = container[index];
}

Input Validation

// βœ… Good: Validate input before use
std::string process_input(const std::string& input) {
    if (input.empty() || input.length() > MAX_LENGTH) {
        throw std::invalid_argument("Invalid input");
    }
    return input;
}

Exception Safety

// βœ… Good: Exception-safe operations
class SafeContainer {
public:
    void add_item(const std::string& item) {
        auto new_items = items;  // Copy first
        new_items.push_back(item);  // Modify copy
        items = std::move(new_items);  // Commit if successful
    }
private:
    std::vector<std::string> items;
};

❌ What We Avoid

Unsafe Practices

// ❌ Avoid: Raw pointers without RAII
int* data = new int[100];
// ... use data ...
// Missing delete[] - memory leak!

// ❌ Avoid: No bounds checking
int value = array[index];  // Could be out of bounds

// ❌ Avoid: Unsafe string operations
char buffer[100];
strcpy(buffer, user_input);  // Potential buffer overflow

πŸŽ“ Educational Security Guidelines

πŸ“š Teaching Secure Practices

Chapter-Specific Security Focus

Chapter 5: Basic Language Features

  • Safe initialization and declaration
  • Proper scope management
  • Exception handling basics

Chapter 6: Functions

  • Parameter validation
  • Return value safety
  • Reference parameter safety

Chapter 7: Classes

  • RAII principles
  • Exception safety guarantees
  • Resource management

Chapter 8: I/O Streams

  • Input validation
  • File operation safety
  • Error handling in streams

Chapter 9: Containers and Strings

  • Iterator safety
  • Container bounds checking
  • String manipulation safety

Chapter 10: Generic Algorithms

  • Safe algorithm usage
  • Iterator validation
  • Lambda expression safety

πŸ”’ Security in Examples

βœ… Safe Example Structure

// βœ… Good: Safe, educational example
#include <iostream>
#include <vector>
#include <stdexcept>

class SafeExample {
public:
    // Validate input in constructor
    SafeExample(const std::string& data) 
        : data_(validate_input(data)) {}
    
    // Safe access with bounds checking
    char get_char(size_t index) const {
        if (index >= data_.length()) {
            throw std::out_of_range("Index out of bounds");
        }
        return data_[index];
    }
    
private:
    std::string data_;
    
    // Input validation helper
    static std::string validate_input(const std::string& input) {
        if (input.empty()) {
            throw std::invalid_argument("Input cannot be empty");
        }
        if (input.length() > MAX_LENGTH) {
            throw std::invalid_argument("Input too long");
        }
        return input;
    }
    
    static constexpr size_t MAX_LENGTH = 1000;
};

πŸ”§ Security Testing

πŸ§ͺ Testing Requirements

Compilation Security

# Test with security-focused flags
g++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined main.cpp -o main

# Test with additional security checks
g++ -std=c++20 -Wall -Wextra -Werror -fstack-protector-strong main.cpp -o main

Runtime Security Testing

  • AddressSanitizer: Detect memory errors
  • UndefinedBehaviorSanitizer: Catch undefined behavior
  • Valgrind: Memory leak detection
  • Static Analysis: Use tools like clang-tidy

πŸ“‹ Security Checklist

  • Memory Safety: No memory leaks or undefined behavior
  • Input Validation: All user input is validated
  • Bounds Checking: Array/container access is bounds-checked
  • Exception Safety: Proper exception handling
  • Resource Management: RAII principles followed
  • Error Handling: Graceful error handling throughout
  • Documentation: Security considerations documented

🚫 Prohibited Content

❌ What We Don't Allow

Malicious Code Examples

  • Code designed to exploit vulnerabilities
  • Examples that could be used for attacks
  • Code that demonstrates unsafe practices without warnings

Dangerous Practices

  • Raw pointer manipulation without RAII
  • Unsafe string operations
  • Unchecked array access
  • Unsafe type conversions

Educational Misinformation

  • Examples that teach incorrect security practices
  • Code that appears safe but has hidden vulnerabilities
  • Missing security warnings in dangerous examples

πŸ”„ Security Update Process

πŸ“ When Security Issues Are Found

  1. Assessment: Evaluate the severity and impact
  2. Fix Development: Create a secure solution
  3. Testing: Thorough testing with security tools
  4. Documentation: Update comments and README files
  5. Educational Review: Ensure fix teaches good practices
  6. Deployment: Apply fix and update examples

πŸ“š Educational Updates

When security issues are fixed, we also:

  • Update Comments: Explain why the fix is necessary
  • Add Warnings: Highlight common security pitfalls
  • Improve Examples: Show both wrong and right approaches
  • Update Documentation: Include security considerations

🀝 Community Security

πŸ’¬ Reporting Guidelines

  • Be Respectful: Report issues constructively
  • Be Specific: Provide detailed, actionable information
  • Be Patient: Allow time for proper investigation
  • Be Educational: Help others learn from the issue

πŸŽ“ Learning from Security Issues

When security issues are resolved:

  • Document the Problem: Explain what went wrong
  • Show the Fix: Demonstrate the correct approach
  • Explain the Why: Help learners understand the reasoning
  • Prevent Future Issues: Add checks to prevent similar problems

πŸ“ž Security Contact

πŸ”— Contact Information

  • Security Email: [[email protected]]
  • Response Time: Within 48 hours
  • Public Issues: Use GitHub issues for non-security concerns
  • Community: Join discussions in GitHub discussions

πŸ“‹ Security Team

  • Project Maintainer: Primary security contact
  • Community Moderators: Help with security discussions
  • Contributors: Report issues through proper channels

Thank you for helping keep this learning project secure! πŸ›‘οΈ

"Security is not just about preventing attacks, but about teaching safe coding practices."

Your security reports help create a safer learning environment for all C++ developers.

There aren’t any published security advisories