-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Implement API to GDPR delete users #3224
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Api | ||
| module Internal | ||
| module Users | ||
| class DeletionsController < ApplicationController | ||
| protect_from_forgery with: :exception | ||
| before_action :authenticate_request! | ||
|
|
||
| def create | ||
| UserCleanupJob.perform_later( | ||
| params[:user_id] | ||
| ) | ||
|
|
||
| head :ok | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def authenticate_request! | ||
| verify_token! | ||
| verify_signature! | ||
| end | ||
|
|
||
| def verify_token! | ||
| token = request.headers['Authorization']&.remove('Bearer ') | ||
|
|
||
| unless ActiveSupport::SecurityUtils.secure_compare( | ||
| token.to_s, | ||
| ENV.fetch('OPENHPI_API_TOKEN') | ||
| ) | ||
| head :unauthorized | ||
| return | ||
|
Check warning on line 33 in app/controllers/api/internal/users/deletions_controller.rb
|
||
| end | ||
| end | ||
|
|
||
| def verify_signature! | ||
| expected = OpenSSL::HMAC.hexdigest( | ||
| 'SHA256', | ||
| ENV.fetch('OPENHPI_WEBHOOK_SECRET'), | ||
| request.raw_post | ||
| ) | ||
|
|
||
| provided = request.headers['X-Signature'] | ||
|
|
||
| unless ActiveSupport::SecurityUtils.secure_compare(expected, provided.to_s) | ||
| head :unauthorized | ||
| return | ||
|
Check warning on line 48 in app/controllers/api/internal/users/deletions_controller.rb
|
||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class UserCleanupJob < ApplicationJob | ||
| queue_as :default | ||
|
|
||
| retry_on StandardError, wait: :exponentially_longer, attempts: 10 | ||
|
|
||
| def perform(user_id) | ||
| cleanup_user_data(user_id) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def cleanup_user_data(user_id) | ||
| user = ExternalUser.find_by(external_id: user_id, consumer_id: 1) # Consumer with ID 1 is openHPI. | ||
|
|
||
| if user.present? | ||
| user.update(name: 'Deleted User', email: nil) | ||
| end | ||
| end | ||
| end |
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.
Bug: Sequential calls to
head :unauthorizedinverify_token!andverify_signature!without areturncan cause aDoubleRenderErrorif both checks fail.Severity: MEDIUM
Suggested Fix
Add an explicit
returnstatement after eachhead :unauthorizedcall in both theverify_token!andverify_signature!methods to ensure execution is halted after the response is rendered.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.