Skip to content

Harden OneSignal notification config#91

Open
MAJINSI wants to merge 2 commits into
BAWES-Universe:masterfrom
MAJINSI:harden-onesignal-notification-config-55
Open

Harden OneSignal notification config#91
MAJINSI wants to merge 2 commits into
BAWES-Universe:masterfrom
MAJINSI:harden-onesignal-notification-config-55

Conversation

@MAJINSI
Copy link
Copy Markdown

@MAJINSI MAJINSI commented May 15, 2026

Summary

  • move OneSignal candidate app id / REST API key values in environment params files to runtime env vars
  • make candidate push sending fail closed when OneSignal config is missing
  • keep TLS peer verification enabled for OneSignal API requests
  • add docs, a static regression guard, and a short demo video

/claim #55

Demo

Verification

  • tests/check-onesignal-env-config.sh
  • git diff --check
  • php -l common/models/MobileNotification.php could not be run locally because this environment does not have php installed

Scope

This is a narrow OneSignal notification credential/transport hardening slice. It does not touch AWS/IAM/S3 keys, bucket policies, Civil ID backend/UI flows, Cloudinary, SQS/MediaConvert/SES/Xero/service-token/Jira/Algolia/Google/Slack slices, live OneSignal access, candidate data, or real private secret values.

Transparency: AI-assisted with OpenAI Codex; I reviewed the diff and verification before submitting.

Summary by CodeRabbit

  • Security & Configuration Improvements

    • Push notification credentials are now sourced from environment variables, replacing hardcoded values.
    • Added stricter validation and logging when push credentials are missing; notification requests now fail safely when misconfigured.
    • TLS peer verification for push requests is enforced.
  • Documentation

    • Added guidance on OneSignal environment variables and fail-closed behavior.
  • Tests

    • Added a script to validate OneSignal configuration and related runtime safeguards.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 49435289-3f88-4515-990b-adf3fcdeefa8

📥 Commits

Reviewing files that changed from the base of the PR and between 3be644f and 1d3f4b0.

📒 Files selected for processing (2)
  • common/models/MobileNotification.php
  • tests/check-onesignal-env-config.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • common/models/MobileNotification.php
  • tests/check-onesignal-env-config.sh

📝 Walkthrough

Walkthrough

This pull request secures OneSignal notification delivery by migrating hardcoded credentials to environment variables, adding strict parameter validation and error handling in the notification model, enabling TLS peer verification, and enforcing the configuration pattern through documentation and automated tests.

Changes

OneSignal Credential Security & TLS Verification

Layer / File(s) Summary
Mobile Notification Model - Validation & SSL Verification
common/models/MobileNotification.php
notifyCandidate() and sendNotification() now validate that OneSignal credentials are non-empty, log warnings and return false when missing, preserve Codeception shortcut, enable CURLOPT_SSL_VERIFYPEER, check curl_exec() for errors and HTTP response codes, and return explicit boolean outcomes with handles closed.
Environment Configuration - Credential Migration
environments/*/common/config/params-local.php
All 12 environment configuration files (circle-ci, dev-server-nginx-debug, dev-server-nginx, dev-server-railway, dev-server, dev, docker, krushn-nginx, krushn, prod-nginx, prod-railway, prod) migrate oneSignalCandidateAPPID and oneSignalCandidateAPIKey from hardcoded values to environment variable lookups (ONESIGNAL_CANDIDATE_APP_ID / ONESIGNAL_CANDIDATE_API_KEY) with empty-string defaults.
Documentation and Configuration Tests
docs/onesignal-env.md, tests/check-onesignal-env-config.sh
Adds docs describing required env vars and TLS verification; adds a test script that fails if credentials are hardcoded, if env lookups are missing from environment configs, or if CURLOPT_SSL_VERIFYPEER is disabled; also asserts presence of CURLOPT_CONNECTTIMEOUT, CURLOPT_TIMEOUT, and CURLINFO_HTTP_CODE in MobileNotification.php.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 I tunneled through configs to seek,
No secrets left in files antique,
Env vars whisper the secure way,
CURL with TLS keeps threats at bay,
Hooray — notifications safe today!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Harden OneSignal notification config' directly and clearly describes the main change: improving security and robustness of OneSignal notification configuration by moving credentials to environment variables, enabling validation, and enforcing TLS peer verification.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
common/models/MobileNotification.php (1)

87-96: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add explicit cURL timeouts to prevent request-thread hangs on network stalls.

The OneSignal API call at lines 87-96 has no connect or request timeout configured. If the OneSignal service becomes unresponsive or the network stalls, the request will block indefinitely.

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
+       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
+       curl_setopt($ch, CURLOPT_TIMEOUT, 15);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@common/models/MobileNotification.php` around lines 87 - 96, The cURL call in
MobileNotification (where $ch is initialized and configured for the OneSignal
API) lacks timeouts and can hang; add explicit CURLOPT_CONNECTTIMEOUT (e.g., 5
seconds) and CURLOPT_TIMEOUT (e.g., 30 seconds) via curl_setopt($ch,
CURLOPT_CONNECTTIMEOUT, ...) and curl_setopt($ch, CURLOPT_TIMEOUT, ...)
alongside the existing curl_setopt calls so the request will fail fast on
network stalls and not block the thread indefinitely.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@common/models/MobileNotification.php`:
- Around line 29-32: The early return in notifyCandidate() prevents test-mode
bypass in sendNotification() when OneSignal config is missing; change the check
so it only returns false when OneSignal params are missing AND test-mode is NOT
active. Update the condition around Yii::$app->params['oneSignalCandidateAPPID']
/ ['oneSignalCandidateAPIKey'] to allow execution to continue when
Yii::$app->params['inCodeception'] (or equivalent test flag) is truthy so
sendNotification() can perform its Codeception bypass; ensure you reference
notifyCandidate() and sendNotification() when making the change.
- Around line 98-109: The code in MobileNotification that currently treats any
non-false curl_exec result as success should validate the HTTP response code:
after $response = curl_exec($ch) (and after the existing transport error check),
call curl_getinfo($ch, CURLINFO_HTTP_CODE) to get $status; if $status is not in
the 2xx range, log a warning with both $status and the $response (e.g. via
Yii::warning) and return false; ensure curl_close($ch) is called before
returning and keep the existing successful return true path when $status is
200–299.

In `@tests/check-onesignal-env-config.sh`:
- Line 12: Update the grep regex used in the test that currently searches for
the literal "CURLOPT_SSL_VERIFYPEER,\s*FALSE" so it matches any case variant of
the PHP boolean (e.g. false, False). Replace the pattern with a case-insensitive
match (for example add the (?i) inline flag or change "FALSE" to
"[Ff][Aa][Ll][Ss][Ee]") in the rg invocation that contains
"CURLOPT_SSL_VERIFYPEER,\\s*FALSE" so the test will catch all casings in
MobileNotification.php.
- Around line 9-10: The test currently checks globally for
getenv('ONESIGNAL_CANDIDATE_APP_ID') and getenv('ONESIGNAL_CANDIDATE_API_KEY')
and can miss missing occurrences in individual params-local.php files; update
tests/check-onesignal-env-config.sh to assert that every params-local.php under
environments/ contains those getenv calls (e.g., loop over each file found by
find environments -name params-local.php or use rg --glob
'environments/**/params-local.php' to search only those files) and fail if any
params-local.php is missing either getenv('ONESIGNAL_CANDIDATE_APP_ID') or
getenv('ONESIGNAL_CANDIDATE_API_KEY').

---

Outside diff comments:
In `@common/models/MobileNotification.php`:
- Around line 87-96: The cURL call in MobileNotification (where $ch is
initialized and configured for the OneSignal API) lacks timeouts and can hang;
add explicit CURLOPT_CONNECTTIMEOUT (e.g., 5 seconds) and CURLOPT_TIMEOUT (e.g.,
30 seconds) via curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, ...) and
curl_setopt($ch, CURLOPT_TIMEOUT, ...) alongside the existing curl_setopt calls
so the request will fail fast on network stalls and not block the thread
indefinitely.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 003be1e6-8ebb-4687-b300-cf34b71a5ae8

📥 Commits

Reviewing files that changed from the base of the PR and between 7b023ff and 3be644f.

⛔ Files ignored due to path filters (1)
  • docs/demo/studenthub-55-onesignal-hardening-demo.mp4 is excluded by !**/*.mp4
📒 Files selected for processing (15)
  • common/models/MobileNotification.php
  • docs/onesignal-env.md
  • environments/circle-ci/common/config/params-local.php
  • environments/dev-server-nginx-debug/common/config/params-local.php
  • environments/dev-server-nginx/common/config/params-local.php
  • environments/dev-server-railway/common/config/params-local.php
  • environments/dev-server/common/config/params-local.php
  • environments/dev/common/config/params-local.php
  • environments/docker/common/config/params-local.php
  • environments/krushn-nginx/common/config/params-local.php
  • environments/krushn/common/config/params-local.php
  • environments/prod-nginx/common/config/params-local.php
  • environments/prod-railway/common/config/params-local.php
  • environments/prod/common/config/params-local.php
  • tests/check-onesignal-env-config.sh

Comment thread common/models/MobileNotification.php Outdated
Comment thread common/models/MobileNotification.php
Comment thread tests/check-onesignal-env-config.sh Outdated
Comment thread tests/check-onesignal-env-config.sh Outdated
@MAJINSI
Copy link
Copy Markdown
Author

MAJINSI commented May 15, 2026

Addressed CodeRabbit feedback in 1d3f4b0:

  • kept Codeception bypass reachable when OneSignal params are empty
  • added cURL connect/request timeouts
  • treat non-2xx OneSignal HTTP responses as failed sends with warnings
  • tightened the regression guard for per-file env checks and case-insensitive SSL peer verification detection

Verification rerun:

  • tests/check-onesignal-env-config.sh
  • git diff --check

@MAJINSI
Copy link
Copy Markdown
Author

MAJINSI commented May 16, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

✅ 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.

@MAJINSI
Copy link
Copy Markdown
Author

MAJINSI commented May 16, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

✅ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant