fix: cap search keywords and feed queries to prevent CWE-407 amplification
- shop.py: strip empty tokens, cap keywords to 10 before passing to model - product.py: add .limit(200) per keyword query — was unbounded .all() - feeds.py: add .limit(1000) on product/content feed queries — was unbounded
This commit is contained in:
parent
eec598604b
commit
f9cbebb6b5
3 changed files with 6 additions and 2 deletions
|
|
@ -682,7 +682,8 @@ def get_products_by_keywords(dbsession, keywords, shop=None):
|
|||
if not shop:
|
||||
from .shop import Shop
|
||||
query = query.join(Shop, Product.shop_id == Shop.id).filter(Shop.environment == 0)
|
||||
products = query.all()
|
||||
# Limit per-keyword results to prevent memory exhaustion (CWE-407).
|
||||
products = query.limit(200).all()
|
||||
|
||||
for product in products:
|
||||
if product.id not in scores:
|
||||
|
|
|
|||
|
|
@ -46,12 +46,14 @@ def get_public_items(shop):
|
|||
products = (
|
||||
shop.products.filter(Product.visibility == 1, Product.is_sellable == True)
|
||||
.order_by(Product.updated_timestamp.desc())
|
||||
.limit(1000)
|
||||
.all()
|
||||
)
|
||||
|
||||
content = (
|
||||
shop.products.filter(Product.visibility == 1, Product.is_sellable == False)
|
||||
.order_by(Product.updated_timestamp.desc())
|
||||
.limit(1000)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -133,8 +133,9 @@ def search(request):
|
|||
if keywords is None:
|
||||
return HTTPFound(get_referer_or_home(request))
|
||||
|
||||
keyword_list = [k for k in keywords.split(" ") if k][:10]
|
||||
products = get_products_by_keywords(
|
||||
request.dbsession, keywords.split(" "), request.shop
|
||||
request.dbsession, keyword_list, request.shop
|
||||
)
|
||||
|
||||
hit_count = len(products)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue