[INBT-135] Fix: Sanitize source_id to prevent URL-as-filename errors#1
Merged
Conversation
…BT-135] Add a Pydantic field validator on ContentMetadata.source_id that hashes any unsafe value (URLs, special chars, path traversals) into a 16-char SHA-256 hex string while passing clean alphanumeric IDs through unchanged. Fix all 6 scrapers/downloaders that fell back to the raw URL when regex extraction failed, and add 10 unit tests for the sanitization logic. Also add CI workflow (lint + test + typecheck) and fix ruff config compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pin ruff>=0.9.0 for ASYNC240 support, add mypy ignore_missing_imports for untyped third-party libs (aioboto3, noble_tls, instagrapi, yt_dlp, bs4), fix type annotations to pass mypy strict mode, and apply ruff format across all files for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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.
Summary
Fix a critical bug where all scrapers and downloaders could use raw URLs as
source_id, producing invalid filesystem paths and S3 keys. Adds a Pydantic-level safety net that hashes any unsafe value into a deterministic 16-char hex string.Linear Issue
INBT-135
Changes
_sanitize_source_idfield validator onContentMetadata.source_id— clean IDs pass through, anything unsafe gets SHA-256 hashed_last_path_segment()helper in apify_downloader for DRY extractiontest_source_id_sanitization.py)Testing
https://vm.tiktok.com/ZNRufq2ex/)Notes
The validator uses a simple allow-list regex (
^[A-Za-z0-9_\-]{1,200}$). If it matches, the value passes through unchanged. Otherwise it's replaced withsha256(value)[:16]— deterministic, always safe, zero edge cases.