Repository navigation
contain gemini batch-job results file within results_folder - #71832
Conversation
|
Thanks for the fix! Could we use Using |
|
Good point on the symlink gap. Switched the check to |
|
Thanks, the change addresses the symlink gap! Could you also add a regression test for the symlink case? The current tests cover |
|
Added a symlink regression test for each operator: results_folder/link is a symlink to a dir outside results_folder, and a display_name of link/evil now raises ValueError before any write, with nothing landing in the outside dir. Both pass on the resolved-path check and would slip through the old abspath()/commonpath() version. |
|
Nice!! |
6d19f3f to
cb809ba
Compare
Rename _results_file_path to _build_results_file_path per the action-verb naming rule, and annotate the job parameter as BatchJob (already imported). Add one happy-path test per operator. The four existing tests are all rejection cases, and the file-writing branch had no other coverage, so a helper that raised unconditionally would have passed the whole suite. Verified: sabotaging the helper to always raise fails exactly these two. Generated-by: Claude Opus 5
potiuk
left a comment
There was a problem hiding this comment.
The containment guard is correct at both call sites, and the four new tests genuinely fail without it — on the old os.path.abspath() path the traversal case writes tmp_path/evil.jsonl and the symlink case writes outside/evil.jsonl, neither raising. Real regression tests rather than tests written around the new code.
I rebased the branch on main (it was 699 commits behind, which the base-branch policy would have refused) and pushed two fixups:
- Renamed
_results_file_pathto_build_results_file_pathper the action-verb naming rule inAGENTS.md, and annotated the parameter asjob: BatchJob— already imported at module level, so no new import. - Added one happy-path test per operator. All four of your tests are rejection cases, and I checked the rest of the file: the file-writing branch of
_prepare_results_for_xcomhad no other coverage, so a helper that raised unconditionally would have passed the entire suite. I verified the new tests close that hole by sabotaging the helper to always raise — exactly the two new tests fail, the four rejection tests still pass.
Smaller observations
str(path_to_file)is now a fully resolved path where it used to beos.path.abspath(...), which does not follow symlinks. That string is the task's XCom value, so a deployment whoseresults_foldersits under a symlink will see a different return value than before. Almost certainly an improvement, and needed for the containment check to mean anything, but it is user-visible and worth a line in the description.Path(f"{results_folder}")turns aNonefolder into a literal directory namedNoneunder the worker's cwd. That is unchanged from the line you replaced, so not on you — but the new helper is the tidiest place to make it an explicit error if you ever feel like it.- On framing:
display_namereaches the worker from a template field, so the value is Dag-author-supplied, and Dag authors already execute arbitrary code on the worker under Airflow's security model. The guard earns its keep when a Dag templates that value fromdag_run.confor a Variable. Good hardening either way — just not a CWE-22 in the vulnerability sense, so I would not frame it as one.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Airflow handles maintainer review:
contributing-docs/05_pull_requests.rst.
Both fields are optional on BatchJob, so job.name.replace(...) could raise AttributeError when neither is set. Annotating the parameter as BatchJob made mypy surface it; fail with a clear message instead. Generated-by: Claude Opus 5
|
Heads-up:
So the annotation earned its keep — thanks for the patience on the extra round-trip.
|
Path traversal via unsanitized Gemini batch-job display_name
GenAIGeminiCreateBatchJobOperatorandGenAIGeminiCreateEmbeddingsBatchJobOperatorname the local results file afterjob.display_name, a field returned in the batch-job metadata.job.nameis already sanitized against/at that spot, butdisplay_name(used first) is not, so a..in it lands the.jsonloutsideresults_folderon the worker. The check now resolves the join and refuses anything escapingresults_folder, applied at both sites, matching thesync_to_local_dirguards already in the GCS and S3 hooks.Was generative AI tooling used to co-author this PR?