Potential fix for code scanning alert no. 5: Server-side request forgery #77
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.
Potential fix for https://github.com/smileidentity/smile-identity-core-ruby/security/code-scanning/5
To address the SSRF vulnerability, we need to ensure that the
upload_urlused as an endpoint for thePUTrequest inupload_fileis validated before use. Sinceprep_upload_response['upload_url']may come from an untrusted source, the safest approach is to check if it points to an expected host or matches a whitelist of base URLs before making any requests. Given the code context, you can enforce that all upload URLs must match a known host/domain—ideally the same as (or a subdomain of) what is expected for Smile Identity's servers (e.g., a prefix from@url). Implement a validation helper method that checks this, and reject nonconforming URLs by raising an error before the request is sent.All changes need to be made within the actions surrounding the construction of the
urlvariable and the call toTyphoeus::Request. Given the code blocks you have, this should be inside theupload_filemethod in lib/smile-identity-core/web_api.rb.Suggested fixes powered by Copilot Autofix. Review carefully before merging.