Skip to content

Commit

Permalink
Merge pull request #517 from govuk-one-login/OJ-2932
Browse files Browse the repository at this point in the history
OJ-2932: Redact CI and reasons from logs
  • Loading branch information
surajkumar authored Dec 5, 2024
2 parents 24d5df3 + 31b7577 commit 8718222
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lambdas/pii-redact/src/pii-redactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ipAddressPatterns } from "./regex/ip-address";
import { namePatterns } from "./regex/name-pattern";
import { dobPatterns } from "./regex/date-of-birth";
import { addressPatterns } from "./regex/address";
import { ciPatterns } from "./regex/contra-indicator";
import { otherPatterns } from "./regex/uncategorised-patterns";

export const defaultPatterns = [
Expand All @@ -11,6 +12,7 @@ export const defaultPatterns = [
...namePatterns,
...dobPatterns,
...addressPatterns,
...ciPatterns,
...otherPatterns,
];

Expand Down
48 changes: 48 additions & 0 deletions lambdas/pii-redact/src/regex/contra-indicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export const ciPatterns = [
{
regex: /\\"reason\\":\s*\\"([^"]*)\\"/g,
replacement: '\\"reason\\": \\"***\\"',
},
{
regex: /\\\\"reason\\\\":\s*\\\\"([^"]*)\\\\"/g,
replacement: '\\\\"reason\\\\": \\\\"***\\\\"',
},
{
regex: /\\\\\\"reason\\\\\\":\s*\\\\\\"([^"]*)\\\\\\"/g,
replacement: '\\\\\\"reason\\\\\\": \\\\\\"***\\\\\\"',
},
{
regex: /\\"ci\\":\s*\\"([^"]*)\\"/g,
replacement: '\\"ci\\": \\"***\\"',
},
{
regex: /\\\\\\"ci\\\\\\":\s*\\\\\\"([^"]*)\\\\\\"/g,
replacement: '\\\\\\"ci\\\\\\": \\\\\\"***\\\\\\"',
},
{
regex: /\\\\\\"ci\\\\\\":\[\\\\\\"[^\\"]*\\\\\\"]/g,
replacement: '\\\\\\"ci\\\\\\": [\\\\\\"***\\\\\\"]',
},
{
regex: /\\"ci\\":\[\\"[^\\"]*\\"]/g,
replacement: '\\"ci\\": [\\"***\\"]',
},
{
regex: /\\"contraIndicationMapping\\"\s*:\s*\[[^\]]*]/g,
replacement: '\\"contraindicationMapping\\": [\\"***\\"]',
},
{
regex: /\\"contraindicationMappings\\":\s*\\"([^"]*)\\"/g,
replacement: '\\"contraindicationMappings\\": \\"***\\"',
},
{
regex: /\\"contraindicatorReasonMappings\\":\s*\\"([^"]*)\\"/g,
replacement: '\\"contraindicatorReasonMappings\\": \\"***\\"',
},
{
regex:
/\\"Name\\":\s*\\"\/check-hmrc-cri-api\/contraindicationMappings\\",\s*\\"Value\\":\s*\\"([^"]*)\\/g,
replacement:
'\\"Name\\":\\"/check-hmrc-cri-api/contraindicationMappings\\",\\"Value\\":\\"***\\',
},
];
17 changes: 17 additions & 0 deletions lambdas/pii-redact/tests/redact-pii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ describe("redact-pii", () => {
});
});

describe("NiNO", () => {
it("should redact a ci and reason", async () => {
const input =
'{\\"ci\\":\\"dummy-ci\\", \\"reason\\": \\"dummy-reason\\"}';
expect(redactPII(input)).toStrictEqual(
'{\\"ci\\": \\"***\\", \\"reason\\": \\"***\\"}'
);
});

it("should redact the mapping", async () => {
const input = '"\\"contraindicatorReasonMappings\\": \\"dummy\\"';
expect(redactPII(input)).toStrictEqual(
'"\\"contraindicatorReasonMappings\\": \\"***\\"'
);
});
});

describe("Dates of Birth", () => {
it("should redact birthDates field", async () => {
const birthDatesRedacted = '{\\"birthDates\\": \\"***\\"}';
Expand Down

0 comments on commit 8718222

Please sign in to comment.