Skip to content

feat: add script name sanitization to prevent shell metacharacter injection#50

Merged
GingerGraham merged 1 commit intofix/bug-fixes-feb-2026-phase-01from
bug/39-function-name-injection
Feb 5, 2026
Merged

feat: add script name sanitization to prevent shell metacharacter injection#50
GingerGraham merged 1 commit intofix/bug-fixes-feb-2026-phase-01from
bug/39-function-name-injection

Conversation

@GingerGraham
Copy link
Owner

Copilot AI review requested due to automatic review settings February 5, 2026 17:43
@GingerGraham GingerGraham merged commit b9eefd0 into fix/bug-fixes-feb-2026-phase-01 Feb 5, 2026
6 checks passed
@GingerGraham GingerGraham deleted the bug/39-function-name-injection branch February 5, 2026 17:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements defense-in-depth sanitization for script names to prevent potential shell metacharacter injection attacks. The feature addresses issue #39 by sanitizing script names at all entry points, replacing any character that is not alphanumeric, period, underscore, or hyphen with an underscore.

Changes:

  • Added _sanitize_script_name() function to sanitize script names by replacing unsafe characters
  • Applied sanitization at all four entry points where script names are set (CLI option, config file, auto-detection from BASH_SOURCE, and dynamic updates via set_script_name())
  • Added comprehensive test suite with 13 test cases covering various attack patterns, edge cases, and integration scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
logging.sh Added _sanitize_script_name() function and applied sanitization at all script name entry points
tests/test_script_name_sanitization.sh Added comprehensive test suite covering basic sanitization, attack patterns, valid character preservation, and integration with various configuration methods


# shellcheck source=tests/test_helpers.sh disable=SC1091
source "$(dirname "${BASH_SOURCE[0]}")/test_helpers.sh"

Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file is missing the required setup_test_suite call at the beginning. This call creates the temporary directory (TEST_TMP_DIR) that is used by TEST_DIR in individual tests. Without this setup, tests that rely on TEST_DIR (like test_sanitize_from_bash_source, test_sanitize_config_file, and test_sanitize_in_log_output) will fail because TEST_TMP_DIR will be undefined.

Add setup_test_suite before the first test function definition, similar to how other test files in this project structure their setup.

Suggested change
setup_test_suite

Copilot uses AI. Check for mistakes.
test_sanitize_idempotent
test_sanitize_empty_whitespace
test_sanitize_quotes
test_sanitize_complex_attack
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file is missing the required cleanup_test_suite call at the end. While the test runner (run_tests.sh) does call cleanup_test_suite after sourcing each test file, following the established pattern in other test files (like test_unsafe_newlines.sh, test_ansi_injection.sh, and test_toctou_protection.sh) improves consistency and ensures proper cleanup even if the test file is run independently.

Suggested change
test_sanitize_complex_attack
test_sanitize_complex_attack
cleanup_test_suite

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant