Skip to content

Commit 010b0c4

Browse files
committed
revert: Remove v1 resource router security changes
V1 API should remain unchanged in this phase. Only V2 API receives functional improvements and security enhancements. This reverts commit bf05a05.
1 parent bf05a05 commit 010b0c4

1 file changed

Lines changed: 0 additions & 37 deletions

File tree

src/basic_memory/api/routers/resource_router.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from basic_memory.schemas.memory import normalize_memory_url
2121
from basic_memory.schemas.search import SearchQuery, SearchItemType
2222
from basic_memory.models.knowledge import Entity as EntityModel
23-
from basic_memory.utils import validate_project_path
2423
from datetime import datetime
2524

2625
router = APIRouter(prefix="/resource", tags=["resources"])
@@ -55,9 +54,6 @@ async def get_resource_content(
5554
"""Get resource content by identifier: name or permalink."""
5655
logger.debug(f"Getting content for: {identifier}")
5756

58-
# Get project path for validation
59-
project_path = Path(config.home)
60-
6157
# Find single entity by permalink
6258
entity = await link_resolver.resolve_link(identifier)
6359
results = [entity] if entity else []
@@ -85,17 +81,6 @@ async def get_resource_content(
8581
# return single response
8682
if len(results) == 1:
8783
entity = results[0]
88-
89-
# Validate entity file path to prevent path traversal
90-
if not validate_project_path(entity.file_path, project_path):
91-
logger.error(
92-
f"Invalid file path in entity {entity.id}: {entity.file_path}"
93-
)
94-
raise HTTPException(
95-
status_code=500,
96-
detail="Entity contains invalid file path",
97-
)
98-
9984
file_path = Path(f"{config.home}/{entity.file_path}")
10085
if not file_path.exists():
10186
raise HTTPException(
@@ -109,13 +94,6 @@ async def get_resource_content(
10994
temp_file_path = tmp_file.name
11095

11196
for result in results:
112-
# Validate entity file path to prevent path traversal
113-
if not validate_project_path(result.file_path, project_path):
114-
logger.error(
115-
f"Invalid file path in entity {result.id}: {result.file_path}"
116-
)
117-
continue # Skip this entity and continue with others
118-
11997
# Read content for each entity
12098
content = await file_service.read_entity_content(result)
12199
memory_url = normalize_memory_url(result.permalink)
@@ -193,18 +171,6 @@ async def write_resource(
193171
else:
194172
content_str = str(content)
195173

196-
# Validate path to prevent path traversal attacks
197-
project_path = Path(config.home)
198-
if not validate_project_path(file_path, project_path):
199-
logger.warning(
200-
f"Invalid file path attempted: {file_path} in project {config.name}"
201-
)
202-
raise HTTPException(
203-
status_code=400,
204-
detail=f"Invalid file path: {file_path}. "
205-
"Path must be relative and stay within project boundaries.",
206-
)
207-
208174
# Get full file path
209175
full_path = Path(f"{config.home}/{file_path}")
210176

@@ -268,9 +234,6 @@ async def write_resource(
268234
"modified_at": file_stats.st_mtime,
269235
},
270236
)
271-
except HTTPException:
272-
# Re-raise HTTP exceptions (like validation errors) without wrapping
273-
raise
274237
except Exception as e: # pragma: no cover
275238
logger.error(f"Error writing resource {file_path}: {e}")
276239
raise HTTPException(status_code=500, detail=f"Failed to write resource: {str(e)}")

0 commit comments

Comments
 (0)