Skip to content

Commit 530c898

Browse files
committed
add warning, todo
1 parent a5354ab commit 530c898

File tree

1 file changed

+24
-0
lines changed
  • stac_fastapi/core/stac_fastapi/core/extensions

1 file changed

+24
-0
lines changed

stac_fastapi/core/stac_fastapi/core/extensions/catalogs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,21 @@ async def get_catalog_collections(
271271
catalog = self.client.catalog_serializer.db_to_stac(db_catalog, request)
272272

273273
# Extract collection IDs from catalog links
274+
#
275+
# FRAGILE IMPLEMENTATION WARNING:
276+
# This approach relies on parsing URL patterns to determine catalog-collection relationships.
277+
# This is fragile and will break if:
278+
# - URLs don't follow the expected /collections/{id} pattern
279+
# - Base URLs contain /collections/ in other segments
280+
# - Relative links are used instead of absolute URLs
281+
# - Links have trailing slashes or query parameters
282+
#
283+
# TODO: In a future version, this should be replaced with a proper database relationship
284+
# (e.g., parent_catalog_id field on Collection documents)
285+
#
274286
collection_ids = []
275287
if hasattr(catalog, "links") and catalog.links:
288+
base_url = str(request.base_url).rstrip("/")
276289
for link in catalog.links:
277290
if link.get("rel") in ["child", "item"]:
278291
# Extract collection ID from href using proper URL parsing
@@ -281,6 +294,17 @@ async def get_catalog_collections(
281294
try:
282295
parsed_url = urlparse(href)
283296
path = parsed_url.path
297+
298+
# Verify this is our expected URL pattern by checking it starts with base_url
299+
# or is a relative path that would resolve to our server
300+
full_href = (
301+
href
302+
if href.startswith(("http://", "https://"))
303+
else f"{base_url}{href}"
304+
)
305+
if not full_href.startswith(base_url):
306+
continue
307+
284308
# Look for patterns like /collections/{id} or collections/{id}
285309
if "/collections/" in path:
286310
# Split by /collections/ and take the last segment

0 commit comments

Comments
 (0)