Skip to content

Commit bf25b86

Browse files
committed
STAC: secure resource pathing
1 parent e80347d commit bf25b86

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎pygeoapi/provider/filesystem.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Authors: Tom Kralidis <tomkralidis@gmail.com>
44
#
5-
# Copyright (c) 2023 Tom Kralidis
5+
# Copyright (c) 2026 Tom Kralidis
66
#
77
# Permission is hereby granted, free of charge, to any person
88
# obtaining a copy of this software and associated documentation
@@ -34,6 +34,7 @@
3434
import os
3535

3636
from pygeoapi.provider.base import (BaseProvider, ProviderConnectionError,
37+
ProviderInvalidQueryError,
3738
ProviderNotFoundError)
3839
from pygeoapi.util import file_modified_iso8601, get_path_basename, url_join
3940

@@ -76,9 +77,15 @@ def get_data_path(self, baseurl, urlpath, dirpath):
7677
root_link = None
7778
child_links = []
7879

79-
data_path = os.path.join(self.data, dirpath)
80+
if '..' in dirpath:
81+
msg = f'Invalid path requested'
82+
LOGGER.error(f'{msg}: {dirpath}')
83+
raise ProviderInvalidQueryError(msg)
84+
8085
data_path = self.data + dirpath
8186

87+
LOGGER.debug(f'Data path: {data_path}')
88+
8289
if '/' not in dirpath: # root
8390
root_link = baseurl
8491
else:

‎tests/provider/test_filesystem_provider.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Authors: Tom Kralidis <tomkralidis@gmail.com>
44
#
5-
# Copyright (c) 2021 Tom Kralidis
5+
# Copyright (c) 2026 Tom Kralidis
66
#
77
# Permission is hereby granted, free of charge, to any person
88
# obtaining a copy of this software and associated documentation
@@ -30,6 +30,7 @@
3030
import os
3131
import pytest
3232

33+
from pygeoapi.provider.base import ProviderInvalidQueryError
3334
from pygeoapi.provider.filesystem import FileSystemProvider
3435

3536
THISDIR = os.path.dirname(os.path.realpath(__file__))
@@ -73,3 +74,6 @@ def test_query(config):
7374
'osm_id': 'int'
7475
}
7576
assert r['assets']['default']['href'] == 'http://example.org/stac/poi_portugal.gpkg' # noqa
77+
78+
with pytest.raises(ProviderInvalidQueryError):
79+
_ = p.get_data_path(baseurl, urlpath, '../../poi_portugal')

0 commit comments

Comments
 (0)