Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask JWT tokens in logs in case of post-auth errors #1457

Merged
merged 2 commits into from
Mar 3, 2023
Merged

Conversation

sfc-gh-aalam
Copy link
Collaborator

@sfc-gh-aalam sfc-gh-aalam commented Feb 28, 2023

test pr for #1455

The JWT tokens are valid for 1 minute, but still can be enough to steal the tokens from logs (if a hacker has access to the log stream or the log service) and use the token to access the data, potentially to change the user's credentials — if done in an automated way.

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-750898: Connector is leaking JWT tokens to logs #1454

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    Fixes a bug where JWT tokens got leaked into logs in case of post-auth errors.

nolar and others added 2 commits February 28, 2023 12:47
The JWT tokens are valid for 1 minute, but still can be enough to steal the tokens from logs (if a hacker has access to the log stream or the log service) and use the token to access the data, potentially to change the user's credentials — if done in an automated way.
@codecov-commenter
Copy link

Codecov Report

Merging #1457 (f874221) into main (be500a0) will increase coverage by 0.05%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main    #1457      +/-   ##
==========================================
+ Coverage   81.84%   81.89%   +0.05%     
==========================================
  Files          60       60              
  Lines        8599     8596       -3     
  Branches     1271     1271              
==========================================
+ Hits         7038     7040       +2     
+ Misses       1230     1223       -7     
- Partials      331      333       +2     
Impacted Files Coverage Δ
src/snowflake/connector/network.py 82.63% <75.00%> (+2.38%) ⬆️
src/snowflake/connector/ocsp_snowflake.py 76.65% <0.00%> (-1.08%) ⬇️
src/snowflake/connector/errors.py 90.47% <0.00%> (+0.52%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sfc-gh-aalam sfc-gh-aalam marked this pull request as ready for review March 1, 2023 22:52
@sfc-gh-aalam sfc-gh-aalam requested review from a team, sfc-gh-jdu and sfc-gh-stan and removed request for a team March 2, 2023 00:38
data = json.dumps(decoded_data)
except Exception:
logger.info("data is not JSON")
_, masked_data, err_str = SecretDetector.mask_secrets(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check the first returned value to see if the data is masked? Or is this more like a best effort?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if data is not masked, then original data is returned. It basically means that no secrets were detected. I'm not sure how we would use the masked value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the explanation :)

@sfc-gh-aalam sfc-gh-aalam merged commit c4302f4 into main Mar 3, 2023
@sfc-gh-aalam sfc-gh-aalam deleted the test_pr_1455 branch March 3, 2023 17:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SNOW-750898: Connector is leaking JWT tokens to logs
4 participants