iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

`remove_orphan_files` scopes `file_list_view` with raw string prefix matching

Open rdblue opened this issue 6 months ago • 10 comments

This issue was reported to the private Apache Iceberg security mailing list. The submitter is being kept anonymous because the report was sent to a private list. After review, the issue is not considered a serious vulnerability that needs to be kept private, so it is being filed publicly here for tracking and resolution.

Note: this submission was generated by AI. Please review its claims and source references carefully before acting on them.

Summary

Spark scopes file_list_view with raw string prefix matching, letting sibling paths fall inside orphan cleanup.

Affected Maven coordinates

  • versioned integration artifacts: org.apache.iceberg:iceberg-spark-3.4_*, org.apache.iceberg:iceberg-spark-3.5_*, org.apache.iceberg:iceberg-spark-4.0_2.13, org.apache.iceberg:iceberg-spark-4.1_2.13

Attacker prerequisites

  • control over a path, prefix, batch, or file list that sits adjacent to a legitimately scoped prefix
  • ability to trigger the credential-selection or cleanup path with that crafted input

Impact

  • A table location like s3://bucket/table also matches sibling prefixes such as s3://bucket/table-backup/....
  • If the caller supplies a crafted file_list_view, files outside the intended directory can be treated as in-scope and deleted.
  • This weakens scope checks even when the explicit location override is not used.

Proof status

Source review only. The issue is visible directly from source.

Key source references

  • org.apache.iceberg.spark.actions.DeleteOrphanFilesSparkAction

rdblue avatar May 20 '26 21:05 rdblue

Not a security issue. Anyone who can run remove_orphan_files with a custom file_list_view is already trusted to do destructive maintenance on that table’s storage. The startsWith filter is sloppy and worth fixing as a normal bug, since a caller can always just specify "location" to the target prefix and get the same behavior.

So we can keep this open, but i'll remove the security tag

RussellSpitzer avatar May 21 '26 00:05 RussellSpitzer

I talked about this one with @danielcweeks and @nastra and it's probably a good idea to look for cases like this and ensure that we are only creating requests with the path separator. It's not that this is a security issue (it's the service's job to vend an appropriately scoped credential) but we don't want clients to fail if they attempt to list s3://bucket/table and don't have permission.

rdblue avatar May 21 '26 17:05 rdblue

Hi, I'd like to work on this issue. Before I start, could a committer clarify the preferred approach?

  1. Quick fix: Add path separator check to the startsWith comparison in filteredCompareToFileList()
  2. Broader fix: Unify both listedFileDS() and filteredCompareToFileList() to use the same path-based approach

@rdblue @RussellSpitzer which direction would you prefer?

nnguyen168 avatar May 22 '26 07:05 nnguyen168

@nnguyen168, I don't understand your question.

The method filteredCompareToFileList returns a Dataset that was provided by the caller after adding a filter to exclude recently modified files. Because this was provided by the caller, Iceberg is not using a credential to get the paths and it is not going to fail as described.

The method listedFileDS uses either FileSystemWalker.listDirRecursivelyWithFileIO or FileSystemWalker.listDirRecursivelyWithHadoop to get a list of files in storage. This is what needs to be updated to avoid listing paths without /.

rdblue avatar May 27 '26 19:05 rdblue

Thanks @rdblue for the clarification. I understand now that the primary concern is listedFileDS() and the FileSystemWalker methods making storage requests without the trailing /.

One follow-up: I noticed filteredCompareToFileList() line 228 also uses a raw startsWith(location) without path separator validation. While this doesn't make storage calls, it could still match sibling paths if the caller's file list contains them (e.g., table-backup/ matching table).

Should this also be fixed as part of this issue, or is that considered acceptable since the caller provided the file list?

I'll focus on FileSystemWalker.listDirRecursivelyWithFileIO and listDirRecursivelyWithHadoop for the main fix.

nnguyen168 avatar May 28 '26 11:05 nnguyen168

One follow-up: I noticed filteredCompareToFileList() line 228 also uses a raw startsWith(location) without path separator validation. While this doesn't make storage calls, it could still match sibling paths if the caller's file list contains them (e.g., table-backup/ matching table).

It seems reasonable to fix this in a separate PR.

rdblue avatar Jun 11 '26 19:06 rdblue

Hi, I'd like to work on this issue. I've identified the bug in filteredCompareToFileList() in DeleteOrphanFilesSparkAction.java where startsWith(location) without a trailing / can incorrectly match sibling paths.

I'll submit a fix.

maoli67660 avatar Jul 04 '26 00:07 maoli67660

Hey @rdblue I just Created a PR and solved the issue please take a look
Spark: Fix orphan file sibling path matching #18029

CoderNasim2023 avatar Sep 09 '26 13:09 CoderNasim2023

16. Hey @rdblue I just Created a PR and solved the issue please take a look Spark: Fix orphan file sibling path matching #18029

what about the latest updates of this 2 PRs #18029 #16498 @rdblue @RussellSpitzer ?

CoderNasim2023 avatar Oct 13 '26 11:10 CoderNasim2023

This is addressed for the filteredCompareToFileList path in #18768 — the separate fix that @rdblue carved out in this comment. The startsWith(location) filter now requires a path separator after the location prefix, preventing sibling paths from being incorrectly matched. CI is green.

txwyy123 avatar Nov 05 '26 05:11 txwyy123