Skip to content

fix(kvs): write record metadata sidecars for input files - #1416

Merged
janbuchar merged 2 commits into
masterfrom
input-metadata-file
Sep 11, 2026
Merged

fix(kvs): write record metadata sidecars for input files#1416
janbuchar merged 2 commits into
masterfrom
input-metadata-file

Conversation

@janbuchar

Copy link
Copy Markdown
Contributor

- Write Crawlee key-value store metadata sidecars when generating prefilled input files.
- Read input files using metadata sidecars instead of guessing file extensions.
- Preserve metadata sidecar files during key-value store purges.

- Related to apify/crawlee#2710 (comment)
- Does not break BC with crawlee 3.x and the Python version
@janbuchar janbuchar added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Sep 10, 2026
@github-actions github-actions Bot added this to the 149th sprint - Tooling team milestone Sep 10, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Sep 10, 2026
Comment thread src/lib/kvs-metadata.ts
Comment on lines +61 to +71
export function readKvsRecordMetadata(storePath: string, key: string): KvsRecordMetadata | undefined {
let metadata: KvsRecordMetadata;

try {
metadata = JSON.parse(readFileSync(join(storePath, recordMetadataFileName(key)), 'utf8'));
} catch {
return undefined;
}

return typeof metadata?.contentType === 'string' ? metadata : undefined;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude bothered me with this hypothetical traversal issue, when user clone actors with malicious sidecar

{ "key": "INPUT", "contentType": "application/json; charset=utf-8",
  "filename": "../../../../home/.apify/auth.json" }

Tried it now so yes it can be done. I mean it is not probably real issue but also it should not be hard to ensure filename is not a path for future proof 🤔

Resolve this as you like.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's 1) as contrived as it gets and 2) already validated in apify/crawlee-storage (used in crawlee v4, the only existing consumer of this option to date).

But let me add a check on the CLI side as well.

@l2ysho l2ysho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice @janbuchar
leaving one comment to you to decide 🚀

@janbuchar janbuchar changed the title feat(kvs): write record metadata sidecars for input files fix(kvs): write record metadata sidecars for input files Sep 11, 2026
@janbuchar
janbuchar merged commit e9fb806 into master Sep 11, 2026
23 checks passed
@janbuchar
janbuchar deleted the input-metadata-file branch September 11, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants