I've been looking for a way to catch potential PII logging violations using linting rules. Specifically, if I have an object that contains PII, I'd like to mark the fields that are expected to contain PII so it doesn't inadvertently get logged, i.e. avoid a situation as follows:
interface Member {
id: string,
email: string,
// other non-pii fields
}
....
const m: Member = getMemberFromRequest(request);
....
if (condition) {
logger.info(`No fluffy bunnies found for ${m.email}`);
}
My first thought would be to add some sort of annotation on the object property (e.g. @PII), then write linter rules to make sure that the specific property isn't used as part of a string literal somewhere. So far, I've only come across a PII linter that looks through comments or string literals (eslint-plugin-pii).
With typescript, I guess another possibility would be to declare a type alias for string and have a tslint rule to catch that type from being used in logs.
Are either of these workable (or good) approaches? Are there better alternatives that I haven't found?