Skip to content
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

LG-13937 Validate secret token for socure DocV webhook #11118

Merged
merged 15 commits into from
Aug 26, 2024

Conversation

theabrad
Copy link
Contributor

🎫 Ticket

LG-13937

🛠 Summary of changes

Socure has the ability to send a secret token with the webhook. We want to validate that secret whenever the webhook is used.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Add a secret to the webhook on the Socure dashboard
  • Add the secret token to IdentityConfig
  • Point the webhook to the URL of the review app or dev once merged.
  • Verify that it returns a 200


def token_valid?
authorization_header = request.headers['Authorization']&.split&.last
authorization_header == IdentityConfig.store.socure_webhook_secret_key
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
authorization_header == IdentityConfig.store.socure_webhook_secret_key
ActiveSupport::SecurityUtils.secure_compare(
authorization_header,
IdentityConfig.store.socure_webhook_secret_key,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make the config an array so we can smoothly support a transition between an old & new key?

Copy link
Contributor

@amirbey amirbey Aug 23, 2024

Choose a reason for hiding this comment

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

i think @zachmargolis makes a great point here ☝🏿

Comment on lines +7 to +11
if token_valid?
render json: { message: 'Secret token is valid.' }
else
render status: :unauthorized, json: { message: 'Invalid secret token.' }
end
Copy link
Member

Choose a reason for hiding this comment

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

Will we be doing more validation in the future? Should we start doing form validation pattern?

Suggested change
if token_valid?
render json: { message: 'Secret token is valid.' }
else
render status: :unauthorized, json: { message: 'Invalid secret token.' }
end
form = SocureWebhookValidationForm.new
result = form.submit(headers: request.headers)
if result.success?
render json: { message: 'Secret token is valid.' }
else
render status: :unauthorized, json: { message: result.first_error_message }
end

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we will be; my understanding is that we'll use the webhook just for status updates on submitted requests, and the secret token is just an anti-ddos measure.

Certainly, if we do end up using information from the webhook, then we should follow the form validation pattern we already have.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, the actual PII data from Socure will be acquired through a separate API call to them.

theabrad and others added 6 commits August 20, 2024 13:46
Co-authored-by: Mitchell Henke <mitchell.henke@gsa.gov>
changelog: Upcoming Features, Doc Auth, add secret validation for socure webhook
Copy link
Contributor

@jmax-gsa jmax-gsa left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@solipet solipet left a comment

Choose a reason for hiding this comment

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

Tested against the review app, and in the solipet env.

Comment on lines +7 to +11
if token_valid?
render json: { message: 'Secret token is valid.' }
else
render status: :unauthorized, json: { message: 'Invalid secret token.' }
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, the actual PII data from Socure will be acquired through a separate API call to them.

@theabrad theabrad merged commit ea73d99 into main Aug 26, 2024
2 checks passed
@theabrad theabrad deleted the abrad-lg-13937-socure-secret branch August 26, 2024 16:06
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.

7 participants