Skip to content

Commit

Permalink
Use repr for logging user input
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Mar 6, 2024
1 parent 91a4556 commit d81f411
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ckan/common.py
Expand Up @@ -261,6 +261,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
7 changes: 5 additions & 2 deletions ckan/views/user.py
Expand Up @@ -24,7 +24,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 @@ -649,7 +650,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(u'Password reset requested for user %s', repr_untrusted(id))

context = cast(
Context, {
Expand Down Expand Up @@ -692,6 +693,8 @@ def post(self) -> Response:
pass

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

Expand Down

0 comments on commit d81f411

Please sign in to comment.