Pensar - auto fix for Hardcoded Neo4j Database Credentials in Jupyter Notebook #854
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Security Issue Fixed:
CWE-798 (Use of Hard-coded Credentials): The original notebook exposed sensitive Neo4j database credentials (username and password) as plain text values directly in the code, setting them as string literals and storing them in environment variables. This risked credential leakage through source files, version control, and notebook sharing.
Fix Applied:
GRAPH_DATABASE_USERNAMEandGRAPH_DATABASE_PASSWORD.GRAPH_DATABASE_PROVIDERandGRAPH_DATABASE_URLare set only if not already in the environment.GRAPH_DATABASE_USERNAME, if not set, the user is prompted at runtime to enter the username.GRAPH_DATABASE_PASSWORD, if not set, the user is securely prompted (usinggetpass.getpass()) to enter it, ensuring the secret is not echoed/visible on screen or in saved notebook source.os.environwill still work, but credentials never reside in the source file.import getpassand explicitly includedimport warningsto the start of this setup cell to support the credential prompt and warnings suppression.Result:
Credentials are now only supplied at runtime (via environment or prompt) and are never written to source control, addressing the credential exposure risk.
More Details