fix: added squelch and no-pii annotation check - #551
Conversation
|
|
||
| # Comma-separated list of identifier substrings treated as likely PII. | ||
| # Substring matching is used, so 'email' will match 'user_email_address'. | ||
| pii-terms=email,secondary_email,username,retired_username,password,full_name,first_name,last_name,phone,phone_number,birth_date,ip_address,location,address,mailing_address,gender,profile_image,job_title,social_link |
There was a problem hiding this comment.
Format it for better readability.
|
|
||
| # Comma-separated list of identifier substrings treated as likely PII. | ||
| # Substring matching is used, so 'email' will match 'user_email_address'. | ||
| pii-terms=email,secondary_email,username,retired_username,password,full_name,first_name,last_name,phone,phone_number,birth_date,ip_address,location,address,mailing_address,gender,profile_image,job_title,social_link |
There was a problem hiding this comment.
can you recheck if retired_username is considered as PII?
| class PiiAnnotationChecker(PiiConfigMixin, BaseChecker): | ||
| """ | ||
| Fires ``pii-invalid-no-pii-annotation`` (W7633) when a concrete Django model | ||
|
|
|
|
||
|
|
There was a problem hiding this comment.
Nit: Two blank lines here, Remove it.
| Unreleased | ||
| ~~~~~~~~~~ | ||
|
|
||
| 6.2.0 - 2026-06-26 |
There was a problem hiding this comment.
Just double checking, This jumps straight from 5.7.0 to 6.2.0, with no 6.0.0 or 6.1.0, Is this normal?
There was a problem hiding this comment.
6.0.0 and 6.1.0 were previous releases that simply weren't documented in the CHANGELOG. So 6.2.0 here is correct, the jump in the CHANGELOG is just a documentation gap from earlier releases, not a versioning error.
| "job_title", | ||
| "social_link", | ||
| ]) | ||
| self._pii_terms_cache = [t.strip().lower() for t in raw_terms if t.strip()] |
There was a problem hiding this comment.
use identifiable name instead of t
There was a problem hiding this comment.
Addressed this and related ones also.
| "attr_email", "default_email", "skip_email_verification", | ||
| "location", "_location", "example_full_name" | ||
| ]) | ||
| self._safe_keys_cache = {k.strip().lower() for k in raw_keys if k.strip()} |
There was a problem hiding this comment.
same here. Rename K to identifiable name and other places also
There was a problem hiding this comment.
Addressed this and related ones also.
| default_email, | ||
| skip_email_verification, | ||
| location, | ||
| _location, |
There was a problem hiding this comment.
We should remove location/_location from this list.
| email, | ||
| secondary_email, | ||
| username, | ||
| retired_username, |
There was a problem hiding this comment.
Remove retired_username, as it is non-traceable and does not follow the OEP-30 validation.
| attr_email, | ||
| default_email, | ||
| skip_email_verification, | ||
| location, |
There was a problem hiding this comment.
Check whether it has to be part of PII-terms as its flagged as PII in OEP-30 doc.
| _NO_PII_COMMENT_RE = re.compile(r"[\s]*#[\s]*\.\.\s*no_pii", re.IGNORECASE) | ||
|
|
||
| # Lines above ``class`` to scan for a comment-style annotation. | ||
| _ANNOTATION_LOOKAHEAD = 5 |
There was a problem hiding this comment.
Increase it to 10, so that detection of pii and no_pii terms doesn't get missed out if description length increases.
| # OEP-0030 PII identifier substrings — substring-matched against variable names. | ||
| _DEFAULT_PII_TERMS = [ | ||
| "email", "secondary_email", | ||
| "username", "retired_username", |
There was a problem hiding this comment.
Remove retired_username from this place. And consider looking at other places also if exists.
| }, | ||
| ), | ||
| ( | ||
| "pii-django-model-bases", |
There was a problem hiding this comment.
For reviewers: Historical models are not considered in this PR. This will be an incremental/next phase change.
|
|
||
| def _test_references_flag(self, test, flag): | ||
| """ | ||
| Return True if AST node *test* references the squelch *flag*. |
There was a problem hiding this comment.
reorganize the pattern number to reduce traversal . The most frequestly used patterns must be placed on top.
| """ | ||
| Recursively inspect *node*; return the first PII term found, or None. | ||
| Checks Name, Attribute, f-strings, binary ops, dicts, and nested calls. | ||
| String literals are NOT checked. |
There was a problem hiding this comment.
There are a lot of ifs and elifs here, so try using switch case instead.
| if ancestor.name in model_bases: | ||
| is_model_subclass = True | ||
| break | ||
| except Exception: # pylint: disable=broad-except |
There was a problem hiding this comment.
Check if pylint inline comment is required, if not please remove.
Check if we can log the exception raised.
|
|
||
| # Exact identifiers that superficially match PII terms but are approved | ||
| # as non-sensitive (surrogate keys, flag fields, system fields). | ||
| pii-safe-key-patterns = |
There was a problem hiding this comment.
Remove the pii terms and just keep prefix or suffix. Ex: user_id, remove user and safe key will be _id .
| pii-terms = | ||
| email, | ||
| secondary_email, | ||
| username, | ||
| retired_username, | ||
| password, | ||
| full_name, | ||
| first_name, | ||
| last_name, | ||
| phone, | ||
| phone_number, | ||
| birth_date, | ||
| ip_address, | ||
| address, | ||
| mailing_address, | ||
| gender, | ||
| profile_image, | ||
| job_title, | ||
| social_link |
There was a problem hiding this comment.
| pii-terms = | |
| email, | |
| secondary_email, | |
| username, | |
| retired_username, | |
| password, | |
| full_name, | |
| first_name, | |
| last_name, | |
| phone, | |
| phone_number, | |
| birth_date, | |
| ip_address, | |
| address, | |
| mailing_address, | |
| gender, | |
| profile_image, | |
| job_title, | |
| social_link | |
| ```suggestion : Because matching uses substring containment, several terms are redundant. | |
| _DEFAULT_PII_TERMS = ( | |
| "email", | |
| "username", | |
| "password", | |
| "full_name", | |
| "first_name", | |
| "last_name", | |
| "phone", | |
| "birth_date", | |
| "ip_address", | |
| "address", | |
| "gender", | |
| "profile_image", | |
| "job_title", | |
| "social_link", | |
| ) |
Description:
PII variables (e.g. email, username, full_name) could silently leak into logs, print statements, or exceptions with no automated guardrail. Stale
.. no_pii: annotations on Django models also went undetected.Solution:
Private JIRA Ticket:
BOMS-587