Skip to content

Commit

Permalink
Merge pull request from GHSA-8g38-3m6v-232j
Browse files Browse the repository at this point in the history
use repr for logging user input
  • Loading branch information
amercader authored Mar 13, 2024
2 parents fcd7bec + 037e27e commit 81b56c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ckan/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ def aslist(obj: Any, sep: Optional[str] = None, strip: bool = True) -> Any:
return [obj]


def repr_untrusted(danger: Any):
"""
repr-format danger and truncate e.g. for logging untrusted input
"""
r = repr(danger)
rtrunc = r[:200]
return rtrunc + '…' if r != rtrunc else r


local = Local()

# This a proxy to the bounded config object
Expand Down
9 changes: 5 additions & 4 deletions ckan/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import ckan.plugins as plugins
from ckan import authz
from ckan.common import (
_, config, g, request, current_user, login_user, logout_user, session
_, config, g, request, current_user, login_user, logout_user, session,
repr_untrusted
)
from ckan.types import Context, Schema, Response
from ckan.lib import signals
Expand Down Expand Up @@ -675,7 +676,7 @@ def post(self) -> Response:
if id in (None, u''):
h.flash_error(_(u'Email is required'))
return h.redirect_to(u'user.request_reset')
log.info(u'Password reset requested for user "{}"'.format(id))
log.info('Password reset requested for user %s', repr_untrusted(id))

context: Context = {
'user': current_user.name,
Expand Down Expand Up @@ -716,8 +717,8 @@ def post(self) -> Response:
pass

if not user_objs:
log.info(u'User requested reset link for unknown user: {}'
.format(id))
log.info('User requested reset link for unknown user: %s',
repr_untrusted(id))

for user_obj in user_objs:
log.info(u'Emailing reset link to user: {}'
Expand Down

0 comments on commit 81b56c5

Please sign in to comment.