Security: fix SSRF in POST /api/imports — validate VideoUrl against YouTube allowlist#178
Open
davidortinau wants to merge 1 commit into
Open
Security: fix SSRF in POST /api/imports — validate VideoUrl against YouTube allowlist#178davidortinau wants to merge 1 commit into
davidortinau wants to merge 1 commit into
Conversation
…n POST /api/imports Add a YouTube URL allowlist guard in StartImport before the import record is created or the pipeline is started. Any URL that is not an https:// URL on www.youtube.com, youtube.com, or youtu.be is rejected with 400 Bad Request. - ImportEndpoints.cs: insert 6-line guard after the null check (lines 67-72) - TestJwtGenerator.cs: add optional userProfileId parameter so integration tests can supply the claim required by the /api/imports endpoint - ImportEndpointsSsrfTests.cs: 13 new tests covering Azure IMDS, RFC-1918 addresses, loopback, non-https YouTube, non-YouTube HTTPS hosts, unparseable input, and three valid YouTube URLs that must pass the guard Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
An authenticated user could submit any URL to
POST /api/importsand the server would make an outbound HTTP request to it before performing any host or scheme validation. This includes Azure IMDS (http://169.254.169.254/metadata/instance), RFC-1918 addresses, and any other internal network resource — potentially exposing managed-identity credentials or internal services.Fix
Added a YouTube allowlist guard in
StartImport(before theVideoImportrecord is created or the pipeline is started). AnyVideoUrlthat does not satisfy all three conditions is rejected immediately with400 Bad Request:httpswww.youtube.com,youtube.com, oryoutu.beThe fix is API-boundary-only — no changes to
VideoImportPipelineServiceor downstream services were needed.Changes
src/SentenceStudio.Api/ImportEndpoints.cstests/SentenceStudio.Api.Tests/ImportEndpointsSsrfTests.cstests/SentenceStudio.Api.Tests/Infrastructure/TestJwtGenerator.csuserProfileIdparam added toGenerateTokenTests
ImportEndpointsSsrfTestscovers:Rejection (400) cases:
http://169.254.169.254/metadata/instance,http://169.254.169.254/http://10.0.0.1/internal,http://192.168.1.1/adminhttp://localhost/evilhttp://www.youtube.com/...https://evil.com/...ftp://www.youtube.com/...not-a-url-at-allAcceptance (non-400) cases:
https://www.youtube.com/watch?v=...https://youtube.com/watch?v=...https://youtu.be/...Verification
IChatClient/AiServiceDI error that exists onmainbefore this branch — not caused by this change