dosubot[bot] commented on issue #36492:
URL: https://github.com/apache/superset/issues/36492#issuecomment-3636956157

   <!-- Answer -->
   This is a known issue: Superset can leak secrets like database passwords in 
logs or stdout during connection errors, especially on master/latest-dev. This 
happens because some error handling and logging paths do not mask credentials 
in connection strings, and recent user reports confirm this behavior in 
production environments 
[(example)](https://github.com/apache/superset/issues/35988).
   
   Superset does not mask sensitive fields by default in logs or the Action 
Log. To prevent secrets from being logged, you can implement a custom event 
logger by subclassing `DBEventLogger` and recursively masking sensitive fields 
(such as `password`, `db_password`, `access_token`, `secret`) before logging. 
Here’s a practical example from the community 
[(discussion)](https://github.com/apache/superset/discussions/35415):
   
   ```python
   class MaskPasswordsEventLogger(DBEventLogger):
       def _mask_sensitive(self, data):
           try:
               if isinstance(data, dict):
                   return {
                       k: (
                           "***MASKED***" if k.lower() in {"password", 
"passwords", "db_password", "access_token", "secret"}
                           else self._mask_sensitive(v)
                       )
                       for k, v in data.items()
                   }
               elif isinstance(data, list):
                   return [self._mask_sensitive(item) for item in data]
               else:
                   return data
           except Exception as e:
               import logging
               logging.warning(f"Error masking sensitive data: {e}")
               return data
   
       def log(self, user_id, action, *args, **kwargs):
           try:
               masked_kwargs = self._mask_sensitive(kwargs)
               super().log(user_id, action, *args, **masked_kwargs)
           except Exception as e:
               import logging
               logging.warning(f"Error in custom event logger: {e}")
   ```
   
   Set this as your `EVENT_LOGGER` in your Superset config to ensure all event 
logs are masked.
   
   Superset also provides a `redact_sensitive` utility for masking fields using 
JSONPath, but it does not handle secrets inside stringified JSON fields. For 
those, you’ll need to extend your masking logic to parse and mask those values 
as well.
   
   For production, always review your logging configuration, use custom 
loggers, and monitor logs for sensitive data exposure. If you want this to be 
handled by default, consider contributing improvements to Superset’s logging 
system to mask secrets automatically.
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/549e4768-730d-4b18-8710-b54269c6603a?feedback_type=other)</sup>
   
   [![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue%3A%20Superset%20can%20leak%20secrets%20like%20database%20passwords%20in%20logs%20or%20stdout%20during%20connection%20errors%2C%20especially%20on%20master/latest-dev.%20This%20happens%20because%20some%20error%20handling%20and%20logging%20paths%20do%20not%20mask%20credentials%20in%20connection%20strings%2C%20and%20recent%20user%20reports%20confirm%20this%20behavior%20in%20production%20environments%20%5B%28example%29%5D%28https%3A//github.com/apache/superset/issues/35988%29.%0A%0ASuperset%20does%20not%20mask%20sensitive%20fields%20by%20default%20in%20logs%20or%20the%20Action%20Log.%20To%20prevent%20secrets%20from%20being%20logged%2C%20you%20can%20implement%20a%20custom%20event%20logger%20by%20subclassing%20%60DBEventLogge
 
r%60%20and%20recursively%20masking%20sensitive%20fields%20%28such%20as%20%60password%60%2C%20%60db_password%60%2C%20%60access_token%60%2C%20%60secret%60%29%20before%20logging.%20Here%E2%80%99s%20a%20practical%20example%20from%20the%20community%20%5B%28discussion%29%5D%28https%3A//github.com/apache/superset/discussions/35415%29%3A%0A%0A%60%60%60python%0Aclass%20MaskPasswordsEventLogger%28DBEventLogger%29%3A%0A%20%20%20%20def%20_mask_sensitive%28self%2C%20data%29%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20isinstance%28data%2C%20dict%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20k%3A%20%28%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%2A%2A%2AMASKED%2A%2A%2A%22%20if%20k.lower%28%29%20in%20%7B%22password%22%2C%20%22passwords%22%2C%20%22db_password%22%2C%20%22access_token%22%2C%20%22secret%22%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%
 
20%20%20%20%20%20%20%20%20%20%20else%20self._mask_sensitive%28v%29%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%29%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20k%2C%20v%20in%20data.items%28%29%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20isinstance%28data%2C%20list%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%5Bself._mask_sensitive%28item%29%20for%20item%20in%20data%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20data%0A%20%20%20%20%20%20%20%20except%20Exception%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20import%20logging%0A%20%20%20%20%20%20%20%20%20%20%20%20logging.warning%28f%22Error%20masking%20sensitive%20data%3A%20%7Be%7D%22%29%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20data%0A%0A%20%20%20%20def%20log%28self%2C%20user_id%2C%20action%2C%20%2Aargs%2C%20%2A%2Akwargs%29%3A%0A%20%20%20%20%20%20%20%2
 
0try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20masked_kwargs%20%3D%20self._mask_sensitive%28kwargs%29%0A%20%20%20%20%20%20%20%20%20%20%20%20super%28%29.log%28user_id%2C%20action%2C%20%2Aargs%2C%20%2A%2Amasked_kwargs%29%0A%20%20%20%20%20%20%20%20except%20Exception%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20import%20logging%0A%20%20%20%20%20%20%20%20%20%20%20%20logging.warning%28f%22Error%20in%20custom%20event%20logger%3A%20%7Be%7D%22%29%0A%60%60%60%0A%0ASet%20this%20as%20your%20%60EVENT_LOGGER%60%20in%20your%20Superset%20config%20to%20ensure%20all%20event%20logs%20are%20masked.%0A%0ASuperset%20also%20provides%20a%20%60redact_sensitive%60%20utility%20for%20masking%20fields%20using%20JSONPath%2C%20but%20it%20does%20not%20handle%20secrets%20inside%20stringified%20JSON%20fields.%20For%20those%2C%20you%E2%80%99ll%20need%20to%20extend%20your%20masking%20logic%20to%20parse%20and%20mask%20those%20values%20as%20well.%0A%0AFor%20production%2C%20always%20review%20your%20logging%20configur
 
ation%2C%20use%20custom%20loggers%2C%20and%20monitor%20logs%20for%20sensitive%20data%20exposure.%20If%20you%20want%20this%20to%20be%20handled%20by%20default%2C%20consider%20contributing%20improvements%20to%20Superset%E2%80%99s%20logging%20system%20to%20mask%20secrets%20automatically.)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/36492)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to