fix(healthcheck): user input is rejected if path contains comma and semicolon#9223
Conversation
|
@coderabbitai review check if this new regex is safe from security wise |
🧩 Analysis chain🏁 Script executed: Length of output: 871 🏁 Script executed: Length of output: 4398 🏁 Script executed: Length of output: 6417 🏁 Script executed: Length of output: 11801 🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 2206 🏁 Script executed: Length of output: 7982 🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 766 🏁 Script executed: Length of output: 4380 🏁 Script executed: Length of output: 1902 🏁 Script executed: Length of output: 971
Security Analysis:
|
| Layer | Location | Status |
|---|---|---|
| UI validation attribute | app/Livewire/Project/Shared/HealthChecks.php Line 37 |
✅ Updated |
$rules array |
app/Livewire/Project/Shared/HealthChecks.php Line 65 |
✅ Updated |
| API validation rules | bootstrap/helpers/api.php |
✅ Updated |
| Runtime sanitization | ApplicationDeploymentJob.php Line 2851 |
✅ Updated |
| Shell execution | ApplicationDeploymentJob.php Line 2854 |
✅ escapeshellarg() used |
✅ Safe from command injection — here's why
The critical path in generate_healthcheck_commands() is:
// Line 2851: runtime regex check, falls back to '/' if invalid
$path = $this->sanitizeHealthCheckValue($this->application->health_check_path, '#^[a-zA-Z0-9/\-_.~%,;]+$#', '/');
// Line 2854: entire URL wrapped in escapeshellarg — key protection
$url = escapeshellarg("{$scheme}://{$host}:{$health_check_port}".($path ?? '/'));
// Line 2864: $url is single-quoted by escapeshellarg, ; is NOT a shell separator here
"curl -s -X {$escapedMethod} -f {$url} > /dev/null || wget -q -O- {$url} > /dev/null || exit 1"Even if the path is /route/v1/driving/-154.2987,19.3831;-46.2989,-23.3836, after escapeshellarg the shell sees:
curl -s -X 'GET' -f 'http://localhost:80/route/v1/driving/-154.2987,19.3831;-46.2989,-23.3836' > /dev/nullThe semicolon is inside single quotes — it's a literal character passed to curl, never interpreted by the shell. 🎯
✅ RFC 3986 compliant
Both , and ; are valid sub-delimiters in URL path segments — this fix is technically correct for real-world URL paths like OSRM routing APIs.
✅ Existing injection test still passes
The test validates health_check_path rejects shell metacharacters via API rules uses /health; rm -rf / — which contains a space, not in the allowed set, so it still fails validation correctly.
✅ sanitizeHealthCheckValue is a safe fallback
private function sanitizeHealthCheckValue(string $value, string $pattern, string $default): string
{
if (preg_match($pattern, $value)) {
return $value;
}
return $default; // falls back to '/'
}Even if something slips through UI/API validation, the runtime check falls back to /.
💡 Minor suggestion (non-blocking)
There are no new tests covering the , and ; characters specifically. Consider adding a test case to HealthCheckCommandInjectionTest.php to document the intent and protect against future regression:
it('allows valid health check path with comma and semicolon', function () {
$rules = sharedDataApplications();
$validator = Validator::make(
['health_check_path' => '/route/v1/driving/-154.2987,19.3831;-46.2989,-23.3836'],
['health_check_path' => $rules['health_check_path']]
);
expect($validator->fails())->toBeFalse();
});
it('generates safe healthcheck command when path contains semicolon', function () {
$result = callGenerateHealthcheckCommands([
'health_check_path' => '/route/v1/driving/start;end',
]);
// semicolon must be inside the escapeshellarg-quoted URL, not a shell separator
expect($result)->toContain("'/route/v1/driving/start;end'")
->and($result)->not->toContain('; end');
});Overall verdict: ✅ The change is safe. The escapeshellarg() wrapping is the terminator-level last line of defense — hasta la vista, shell injection. 💪
✅ Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
WalkthroughThis pull request relaxes the validation constraints for HTTP healthcheck paths across three files. The allowed character regex has been expanded to include comma ( I'll be back... to self-host your healthchecks on actual servers instead of ephemeral, VC-funded vapor. 🤖 This change is beautiful, really. You're giving your healthcheck paths the flexibility they deserve—adding support for those commas and semicolons that real-world configurations actually need. It's like finally getting a gluten-free taco shell that doesn't crumble the moment you look at it. The validation now matches reality instead of forcing your infrastructure into arbitrary constraints. Three coordinated updates ensure consistency: the deployment job, the Livewire component, and the API helpers all speak the same language now. No more silently dropping to ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/Jobs/ApplicationDeploymentJob.php`:
- Line 2851: Add regression tests covering the new allowed charset for
health_check_path so future changes don't break it: create tests that call
ApplicationDeploymentJob::sanitizeHealthCheckValue (or run deployment flow that
uses it) asserting that valid paths like "/health,ready;v=1" and
"/path-_.~%,;123" are accepted and that payloads containing spaces or other
disallowed characters are rejected; include at least one positive case and one
negative case (e.g., " /bad space" or "bad?space") to ensure the regex
'#^[a-zA-Z0-9/\-_.~%,;]+$#' retains intended behavior. Ensure tests assert the
sanitized/returned value equals the expected default-fallback (e.g., '/') or
expected sanitized output and run them as part of the suite.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ecb5cfb6-52e3-471e-bf71-a65a49fc7e7f
📒 Files selected for processing (3)
app/Jobs/ApplicationDeploymentJob.phpapp/Livewire/Project/Shared/HealthChecks.phpbootstrap/helpers/api.php
| $host = $this->sanitizeHealthCheckValue($this->application->health_check_host, '/^[a-zA-Z0-9.\-_]+$/', 'localhost'); | ||
| $path = $this->application->health_check_path | ||
| ? $this->sanitizeHealthCheckValue($this->application->health_check_path, '#^[a-zA-Z0-9/\-_.~%]+$#', '/') | ||
| ? $this->sanitizeHealthCheckValue($this->application->health_check_path, '#^[a-zA-Z0-9/\-_.~%,;]+$#', '/') |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Add regression tests for the new path charset.
Line 2851 is a solid runtime update; now lock it in with tests (e.g., allow /health,ready;v=1, still reject payloads with spaces). Hasta la vista, regressions.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/Jobs/ApplicationDeploymentJob.php` at line 2851, Add regression tests
covering the new allowed charset for health_check_path so future changes don't
break it: create tests that call
ApplicationDeploymentJob::sanitizeHealthCheckValue (or run deployment flow that
uses it) asserting that valid paths like "/health,ready;v=1" and
"/path-_.~%,;123" are accepted and that payloads containing spaces or other
disallowed characters are rejected; include at least one positive case and one
negative case (e.g., " /bad space" or "bad?space") to ensure the regex
'#^[a-zA-Z0-9/\-_.~%,;]+$#' retains intended behavior. Ensure tests assert the
sanitized/returned value equals the expected default-fallback (e.g., '/') or
expected sanitized output and run them as part of the suite.
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. ❌ Failed to clone repository into sandbox. Please try again. |
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. ❌ Failed to clone repository into sandbox. Please try again. |
|
Thank you for the PR! 💜 |
Changes
Issues
Category
AI Assistance
If AI was used:
Testing
/route/v1/driving/-154.2987,19.3831;-46.2989,-23.3836(it will save the changes, previously it will throw error as the path is invalid)Contributor Agreement
Important