-
Notifications
You must be signed in to change notification settings - Fork 0
feat(auth): implement Facebook data deletion callback and backfill command #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smarcet
wants to merge
7
commits into
main
Choose a base branch
from
feat/facebook-callback-delete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
310569d
feat(auth): implement Facebook data deletion callback and backfill co…
smarcet 477109d
debug: dump response body on CI 500 failure for FacebookDataDeletionA…
smarcet c8daaa0
fix(auth): reject null/empty secret cleanly, configure CI Facebook creds
smarcet 86c4b35
fix(auth): reject non-string signed_request with 400 instead of TypeE…
smarcet 06df951
fix(db): add FK, index and correct column width to facebook_deletion_…
smarcet e7cbe3d
fix(auth): stop logging the Facebook app-scoped id in backfill debug log
smarcet 5b72374
fix(auth): fail cleanly when fopen() fails after is_readable() passes
smarcet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| <?php namespace App\Console\Commands; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
| use App\Services\Auth\IFacebookDataDeletionService; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Log; | ||
|
|
||
| /** | ||
| * Class FacebookDataDeletionBackfill | ||
| * Processes the "Download User Identifiers" CSV Facebook lets admins export | ||
| * from the app dashboard's Advanced Settings, unlinking each app-scoped ID | ||
| * from its matching OpenStackID user (same logic as the live callback). | ||
| * @package App\Console\Commands | ||
| */ | ||
| final class FacebookDataDeletionBackfill extends Command | ||
| { | ||
| /** | ||
| * The console command name. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $name = 'idp:facebook-data-deletion-backfill'; | ||
|
|
||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'idp:facebook-data-deletion-backfill {path : Absolute path to the Facebook user identifiers CSV}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Process a Facebook "Download User Identifiers" CSV export, unlinking each app-scoped ID from its OpenStackID user.'; | ||
|
|
||
| /** | ||
| * @var IFacebookDataDeletionService | ||
| */ | ||
| private $service; | ||
|
|
||
| /** | ||
| * FacebookDataDeletionBackfill constructor. | ||
| * @param IFacebookDataDeletionService $service | ||
| */ | ||
| public function __construct(IFacebookDataDeletionService $service) | ||
| { | ||
| parent::__construct(); | ||
| $this->service = $service; | ||
| } | ||
|
|
||
| /** | ||
| * @return int | ||
| */ | ||
| public function handle() | ||
| { | ||
| $path = $this->argument('path'); | ||
|
|
||
| if (!is_readable($path)) { | ||
| $this->error(sprintf("File %s is not readable.", $path)); | ||
| return 1; | ||
| } | ||
|
|
||
| $matched = 0; | ||
| $not_found = 0; | ||
| $skipped = 0; | ||
|
|
||
| $handle = @fopen($path, 'r'); | ||
| if ($handle === false) { | ||
| $this->error(sprintf("Unable to open file %s.", $path)); | ||
| return 1; | ||
| } | ||
|
|
||
| while (($line = fgets($handle)) !== false) { | ||
| $external_id = trim($line, " \t\n\r\0\x0B\"'"); | ||
|
|
||
| if ($external_id === '') { | ||
| $skipped++; | ||
| continue; | ||
| } | ||
|
|
||
| $result = $this->service->processDeletionRequest($external_id); | ||
|
|
||
| if ($result['status'] === 'completed') { | ||
| $matched++; | ||
| } else { | ||
| $not_found++; | ||
| } | ||
|
|
||
| Log::debug(sprintf("FacebookDataDeletionBackfill::handle processed request with status %s", $result['status'])); | ||
| } | ||
| fclose($handle); | ||
|
|
||
| $this->info(sprintf("Processed CSV: %d matched, %d not found, %d skipped blank lines.", $matched, $not_found, $skipped)); | ||
| return 0; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
app/Http/Controllers/Api/FacebookDataDeletionController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php namespace App\Http\Controllers\Api; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
| use App\Http\Controllers\Controller; | ||
| use App\libs\Auth\FacebookSignedRequestParser; | ||
| use App\Services\Auth\IFacebookDataDeletionService; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\Config; | ||
| use Illuminate\Support\Facades\Log; | ||
|
|
||
| /** | ||
| * Class FacebookDataDeletionController | ||
| * Implements Facebook's Data Deletion Request Callback. | ||
| * @see https://developers.facebook.com/documentation/development/create-an-app/app-dashboard/data-deletion-callback | ||
| * @package App\Http\Controllers\Api | ||
| */ | ||
| final class FacebookDataDeletionController extends Controller | ||
| { | ||
| /** | ||
| * @var IFacebookDataDeletionService | ||
| */ | ||
| private $service; | ||
|
|
||
| /** | ||
| * FacebookDataDeletionController constructor. | ||
| * @param IFacebookDataDeletionService $service | ||
| */ | ||
| public function __construct(IFacebookDataDeletionService $service) | ||
| { | ||
| $this->service = $service; | ||
| } | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * @return \Illuminate\Http\JsonResponse | ||
| */ | ||
| public function handle(Request $request) | ||
| { | ||
| $signed_request = $request->input('signed_request'); | ||
|
|
||
| if (!is_string($signed_request) || $signed_request === '') { | ||
| Log::warning("FacebookDataDeletionController::handle missing signed_request"); | ||
| return response()->json([ | ||
| 'error' => ['code' => 'invalid_request', 'message' => 'signed_request is required.'] | ||
| ], 400); | ||
| } | ||
|
|
||
| $secret = Config::get('services.facebook.client_secret'); | ||
| $data = FacebookSignedRequestParser::parse($signed_request, $secret); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
Comment on lines
+58
to
+60
|
||
| if (is_null($data)) { | ||
| Log::warning("FacebookDataDeletionController::handle invalid signed_request"); | ||
| return response()->json([ | ||
| 'error' => ['code' => 'invalid_signature', 'message' => 'Invalid signed_request.'] | ||
| ], 400); | ||
| } | ||
|
|
||
| $result = $this->service->processDeletionRequest((string)$data['user_id']); | ||
|
|
||
| return response()->json([ | ||
| 'url' => $result['url'], | ||
| 'confirmation_code' => $result['confirmation_code'], | ||
| ], 200); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * @param string $confirmation_code | ||
| * @return \Illuminate\Contracts\View\View | ||
| */ | ||
| public function status(Request $request, string $confirmation_code) | ||
| { | ||
| $result = $this->service->getStatus($confirmation_code); | ||
|
|
||
| if (is_null($result)) { | ||
| abort(404); | ||
| } | ||
|
|
||
| return view('auth.facebook_data_deletion_status', ['result' => $result]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Remove the hard-coded Facebook application secret from all CI workflows.
The same credential is committed in three files and is exposed to job steps. Replace each value with
${{ secrets.FACEBOOK_CLIENT_SECRET }}or a non-sensitive test fixture. Rotate the exposed credential before merge..github/workflows/pull_request_unit_tests.yml#L41-L41: replace the plaintext secret in the pull-request test job..github/workflows/nightly_unit_tests.yml#L36-L36: replace the plaintext secret in the nightly test job..github/workflows/push.yml#L37-L37: replace the plaintext secret in the push test job.🧰 Tools
🪛 Betterleaks (1.7.3)
[high] 41-41: Discovered a Facebook Application secret, posing a risk of unauthorized access to Facebook accounts and personal data exposure.
(facebook-secret)
📍 Affects 3 files
.github/workflows/pull_request_unit_tests.yml#L41-L41(this comment).github/workflows/nightly_unit_tests.yml#L36-L36.github/workflows/push.yml#L37-L37🤖 Prompt for AI Agents
Source: Linters/SAST tools