diff --git a/backend/.prettierrc b/backend/.prettierrc new file mode 100644 index 00000000..e69de29b diff --git a/backend/package.json b/backend/package.json index 4e9d172d..ad198cad 100644 --- a/backend/package.json +++ b/backend/package.json @@ -8,7 +8,8 @@ "build": "tsc", "watch": "tsc -w", "dev": "nodemon src/index.ts", - "start": "node dist/src/index.js" + "start": "node dist/src/index.js", + "format": "prettier --write './src/**/*.{ts,tsx}'" }, "keywords": [], "author": "", @@ -25,6 +26,7 @@ "@types/express": "^4.17.13", "@types/node": "^18.6.1", "nodemon": "^2.0.19", + "prettier": "^2.7.1", "ts-node": "^10.9.1", "tslib": "^2.4.0", "typescript": "^4.7.4" diff --git a/backend/src/api/get-endpoints/index.ts b/backend/src/api/get-endpoints/index.ts index 0cd42a04..4067a589 100644 --- a/backend/src/api/get-endpoints/index.ts +++ b/backend/src/api/get-endpoints/index.ts @@ -6,8 +6,8 @@ export const getEndpointsHandler = async (req: Request, res: Response) => { const getEndpointParams: GetEndpointParams = req.query; try { const endpoints = await GetEndpointsService.getEndpoints(getEndpointParams); - res.send(200).send(endpoints) + res.status(200).send(endpoints); } catch { - res.sendStatus(500) + res.sendStatus(500); } -} +}; diff --git a/backend/src/api/log-request/index.ts b/backend/src/api/log-request/index.ts index a2bd6ec0..f091301d 100644 --- a/backend/src/api/log-request/index.ts +++ b/backend/src/api/log-request/index.ts @@ -6,11 +6,11 @@ export const logRequestSingleHandler = async (req: Request, res: Response) => { const traceParams: TraceParams = req.body; try { await LogRequestService.logRequest(traceParams); - res.sendStatus(200) + res.sendStatus(200); } catch { - res.sendStatus(500) + res.sendStatus(500); } -} +}; export const logRequestBatchHandler = async (req: Request, res: Response) => { const traceParamsBatch: TraceParams[] = req.body; @@ -20,4 +20,4 @@ export const logRequestBatchHandler = async (req: Request, res: Response) => { } catch { res.sendStatus(500); } -} \ No newline at end of file +}; diff --git a/backend/src/data-source.ts b/backend/src/data-source.ts index 961c1821..5ec07211 100644 --- a/backend/src/data-source.ts +++ b/backend/src/data-source.ts @@ -1,6 +1,6 @@ -import "dotenv/config" +import "dotenv/config"; import { DataSource } from "typeorm"; -import { ApiEndpoint, MatchedDataClass, ApiTrace } from "../models" +import { ApiEndpoint, MatchedDataClass, ApiTrace } from "../models"; export const AppDataSource = new DataSource({ type: "postgres", @@ -9,4 +9,4 @@ export const AppDataSource = new DataSource({ entities: [ApiEndpoint, MatchedDataClass, ApiTrace], migrations: [], logging: false, -}) +}); diff --git a/backend/src/enums.ts b/backend/src/enums.ts index 3b152142..03ca3f4d 100644 --- a/backend/src/enums.ts +++ b/backend/src/enums.ts @@ -1,13 +1,13 @@ export enum RestMethod { GET = "GET", HEAD = "HEAD", - POST = "POST", - PUT = "PUT", - PATCH = "PATCH", - DELETE = "DELETE", - CONNECT = "CONNECT", - OPTIONS = "OPTIONS", - TRACE = "TRACE" + POST = "POST", + PUT = "PUT", + PATCH = "PATCH", + DELETE = "DELETE", + CONNECT = "CONNECT", + OPTIONS = "OPTIONS", + TRACE = "TRACE", } export enum DataClass { @@ -20,5 +20,5 @@ export enum DataClass { VIN = "Vehicle Identification Number", ADDRESS = "Address", DOB = "Date of Birth", - DL_NUMBER = "Driver License Number" + DL_NUMBER = "Driver License Number", } diff --git a/backend/src/index.ts b/backend/src/index.ts index 6b2fdc79..5b2cee95 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,39 +1,40 @@ -import express, { Express, Request, Response } from 'express'; -import dotenv from 'dotenv'; -import bodyParser from 'body-parser'; -import { logRequestBatchHandler, logRequestSingleHandler } from "./api/log-request" -import { AppDataSource } from './data-source'; +import express, { Express, Request, Response } from "express"; +import dotenv from "dotenv"; +import bodyParser from "body-parser"; +import { + logRequestBatchHandler, + logRequestSingleHandler, +} from "./api/log-request"; +import { AppDataSource } from "./data-source"; dotenv.config(); const app: Express = express(); const port = process.env.PORT || 8080; -app.use(bodyParser.json()) +app.use(bodyParser.json()); -app.get('/', (req: Request, res: Response) => { - res.send('OK'); +app.get("/", (req: Request, res: Response) => { + res.send("OK"); }); -app.post('/log-request/single', logRequestSingleHandler) -app.post('/log-request/batch', logRequestBatchHandler) +app.post("/log-request/single", logRequestSingleHandler); +app.post("/log-request/batch", logRequestBatchHandler); const main = async () => { try { const datasource = await AppDataSource.initialize(); console.log( - `Is AppDataSource Initialized? ${ - datasource.isInitialized ? "Yes" : "No" - }`, - ) + `Is AppDataSource Initialized? ${datasource.isInitialized ? "Yes" : "No"}` + ); app.listen(port, () => { console.log(`⚡️[server]: Server is running at http://localhost:${port}`); }); } catch (err) { - console.error(`CatchBlockInsideMain: ${err}`) + console.error(`CatchBlockInsideMain: ${err}`); } -} +}; -main().catch(err => { - console.error(`Error in main try block: ${err}`) -}) +main().catch((err) => { + console.error(`Error in main try block: ${err}`); +}); diff --git a/backend/src/services/get-endpoints/index.ts b/backend/src/services/get-endpoints/index.ts index 9bf25e3a..5c1661c2 100644 --- a/backend/src/services/get-endpoints/index.ts +++ b/backend/src/services/get-endpoints/index.ts @@ -1,46 +1,51 @@ import { FindManyOptions, FindOptionsWhere } from "typeorm"; import { GetEndpointParams } from "../../types"; -import { AppDataSource } from "../../data-source" +import { AppDataSource } from "../../data-source"; import { ApiEndpoint } from "../../../models"; export class GetEndpointsService { - static async getEndpoints(getEndpointParams: GetEndpointParams): Promise { + static async getEndpoints( + getEndpointParams: GetEndpointParams + ): Promise { try { const apiEndpointRepository = AppDataSource.getRepository(ApiEndpoint); - let whereConditions: FindOptionsWhere = {} - let paginationParams: FindManyOptions = {} + let whereConditions: FindOptionsWhere = {}; + let paginationParams: FindManyOptions = {}; if (getEndpointParams?.environment) { whereConditions = { ...whereConditions, - environment: getEndpointParams.environment - } + environment: getEndpointParams.environment, + }; } if (getEndpointParams?.host) { whereConditions = { ...whereConditions, - host: getEndpointParams.host - } + host: getEndpointParams.host, + }; } if (getEndpointParams?.offset) { paginationParams = { ...paginationParams, - skip: getEndpointParams.offset - } + skip: getEndpointParams.offset, + }; } if (getEndpointParams?.limit) { paginationParams = { ...paginationParams, - take: getEndpointParams.limit - } + take: getEndpointParams.limit, + }; } - - const endpoints = await apiEndpointRepository.find({ where: whereConditions, ...paginationParams }) + + const endpoints = await apiEndpointRepository.find({ + where: whereConditions, + ...paginationParams, + }); // TODO: Calculate risk score for endpoints and if risk score param present, only return those that meet - return endpoints + return endpoints; } catch (err) { - console.error(`Error in Get Endpoints service: ${err}`) + console.error(`Error in Get Endpoints service: ${err}`); } } -} \ No newline at end of file +} diff --git a/backend/src/services/log-request/index.ts b/backend/src/services/log-request/index.ts index 33dc6107..0cebd152 100644 --- a/backend/src/services/log-request/index.ts +++ b/backend/src/services/log-request/index.ts @@ -32,28 +32,27 @@ export class LogRequestService { // Check for sensitive data in request parameters - const startTime = performance.now() + const startTime = performance.now(); if (requestParameters) { for (const param of requestParameters) { const field = param.name; const matches = ScannerService.scan(param.value); } } - console.log(performance.now() - startTime) - - await apiTraceRepository.save(apiTraceObj) + console.log(performance.now() - startTime); + await apiTraceRepository.save(apiTraceObj); //TODO: Log Request in ApiEndpoint table //TODO: Find sensitive data in request and response and add data classes and data paths to tables } catch (err) { - console.error(`Error in Log Request service: ${err}`) + console.error(`Error in Log Request service: ${err}`); } } static async logRequestBatch(traceParamsBatch: TraceParams[]) { for (let i = 0; i < traceParamsBatch.length; i++) { - this.logRequest(traceParamsBatch[i]) + this.logRequest(traceParamsBatch[i]); } } } diff --git a/backend/src/services/scanner/regexp.ts b/backend/src/services/scanner/regexp.ts index e0df5797..5cc0647f 100644 --- a/backend/src/services/scanner/regexp.ts +++ b/backend/src/services/scanner/regexp.ts @@ -1,126 +1,130 @@ /*** Patterns ***/ // Address patterns -const zipPattern = String.raw`\d{5}(?:-\d{4})?` -const cityPattern = String.raw`(?:[A-Z][a-z.-]+[ ]?){0,70}` -const statePattern = String.raw`Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New[ ]Hampshire|New[ ]Jersey|New[ ]Mexico|New[ ]York|North[ ]Carolina|North[ ]Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode[ ]Island|South[ ]Carolina|South[ ]Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West[ ]Virginia|Wisconsin|Wyoming` -const stateAbbrvPattern = String.raw`AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY` -const cityStateZipPattern = String.raw`${cityPattern},\s*(?:${statePattern}|${stateAbbrvPattern}),?\s*${zipPattern}` -const streetSuffixPattern = String.raw`Alley|Allee|Ally|Aly|Annex|Anex|Annx|Anx|Arcade|Arc|Avenue|Av|Ave|Aven|Avenu|Avn|Avnue|Bayou` -+ `|Bayoo|Byu|Beach|Bch|Bend|Bnd|Bluff|Bluf|Blf|Bluffs|Blfs|Bottom|Bot|Bottm|Btm|Boulevard|Boul` -+ `|Boulv|Blvd|Branch|Brnch|Br|Bridge|Brdge|Brg|Brook|Brk|Brooks|Brks|Burg|Bg|Burgs|Bgs|Bypass` -+ `|Bypa|Bypas|Byps|Byp|Camp|Cmp|Cp|Canyon|Canyn|Cnyn|Cyn|Cape|Cpe|Causeway|Causwa|Cswy|Center` -+ `|Cen|Cent|Centr|Centre|Cnter|Cntr|Ctr|Centers|Ctrs|Circle|Circ|Circl|Crcl|Crcle|Cir|Circles` -+ `|Cirs|Cliff|Clf|Cliffs|Clfs|Club|Clb|Common|Cmn|Commons|Cmns|Corner|Cor|Corners|Cors|Course` -+ `|Crse|Court|Ct|Courts|Cts|Cove|Cv|Coves|Cvs|Creek|Crk|Crescent|Crsent|Crsnt|Cres|Crest|Crst` -+ `|Crossing|Crssng|Xing|Crossroad|Xrd|Curve|Curv|Dale|Dl|Dam|Dm|Divide|Div|Dvd|Dv|Drive|Driv` -+ `|Drv|Dr|Drives|Drs|Estate|Est|Estates|Ests|Expressway|Exp|Expr|Express|Expw|Expy|Extension` -+ `|Extn|Extnsn|Ext|Extensions|Exts|Fall|Falls|Fls|Ferry|Frry|Fry|Field|Fld|Fields|Flds|Flat` -+ `|Flt|Flats|Flts|Ford|Frd|Fords|Frds|Forest|Frst|Forge|Forg|Frg|Forges|Frgs|Fork|Frk|Forks` -+ `|Frks|Fort|Frt|Ft|Freeway|Freewy|Frway|Frwy|Fwy|Garden|Gardn|Grden|Grdn|Gdn|Gardens|Gdns` -+ `|Gateway|Gatewy|Gatway|Gtway|Gtwy|Glen|Gln|Glens|Glns|Green|Grn|Greens|Grns|Grove|Grov|Grv` -+ `|Groves|Grvs|Harbor|Harb|Harbr|Hrbor|Hbr|Harbors|Hbrs|Haven|Hvn|Heights|Hts|Highway|Highwy` -+ `|Hiway|Hiwy|Hway|Hwy|Hill|Hl|Hills|Hls|Hollow|Hllw|Holw|Holws|Inlet|Inlt|Island|Is|Islands` -+ `|Iss|Isle|Junction|Jction|Jctn|Junctn|Juncton|Jct|Junctions|Jcts|Key|Ky|Keys|Kys|Knoll|Knol` -+ `|Knl|Knolls|Knls|Lake|Lk|Lakes|Lks|Land|Landing|Lndng|Lndg|Lane|Ln|Light|Lgt|Lights|Lgts|Loaf` -+ `|Lf|Lock|Lck|Locks|Lcks|Lodge|Ldge|Lodg|Ldg|Loop|Lp|Mall|Manor|Mnr|Manors|Mnrs|Meadow|Mdw` -+ `|Meadows|Medows|Mdws|Mews|Mill|Ml|Mills|Mls|Mission|Msn|Motorway|Mtwy|Mount|Mt|Mountain|Mtn` -+ `|Mountains|Mtns|Neck|Nck|Orchard|Orchrd|Orch|Oval|Ovl|Overpass|Opas|Park|Prk|Parks|Park|Parkway` -+ `|Parkwy|Pkway|Pky|Pkwy|Parkways|Pkwys|Pass|Passage|Psge|Path|Pike|Pine|Pne|Pines|Pnes|Place|Pl` -+ `|Plain|Pln|Plains|Plns|Plaza|Plza|Plz|Point|Pt|Points|Pts|Port|Prt|Ports|Prts|Prairie|Prr|Pr` -+ `|Radial|Rad|Radiel|Radl|Ramp|Ranch|Rnch|Rnchs|Rapid|Rpd|Rapids|Rpds|Rest|Rst|Ridge|Rdge|Rdg` -+ `|Ridges|Rdgs|River|Rvr|Rivr|Riv|Road|Rd|Roads|Rds|Route|Rte|Row|Rue|Run|Shoal|Shl|Shoals|Shls` -+ `|Shore|Shr|Shores|Shrs|Skyway|Skwy|Spring|Spng|Sprng|Spg|Springs|Spgs|Spur|Square|Sqr|Sqre|Squ` -+ `|Sq|Squares|Sqs|Station|Statn|Stn|Sta|Strasse|Stravenue|Strav|Straven|Stravn|Strvn|Strvnue|Stra` -+ `|Stream|Streme|Strm|Street|Str|Strt|St|Streets|Sts|Summit|Sumit|Sumitt|Smt|Terrace|Terr|Ter` -+ `|Throughway|Trwy|Trace|Trce|Track|Trak|Trk|Trks|Trafficway|Trfy|Trail|Trl|Trailer|Trlr|Tunnel` -+ `|Tunl|Turnpike|Trnpk|Turnpk|Tpke|Underpass|Upas|Union|Un|Unions|Uns|Valley|Vally|Vlly|Vly` -+ `|Valleys|Vlys|Via|Viaduct|Vdct|Viadct|Via|View|Vw|Views|Vws|Village|Vill|Villag|Villg|Vlg` -+ `|Villages|Vlgs|Ville|Vl|Vista|Vist|Vst|Vsta|Vis|Walk|Wall|Way|Wy|Well|Wl|Wells|Wls` -const directionPattern = String.raw`(?:[nN](?:orth)?|[eE](?:ast)?|[sS](?:outh)?|[wW](?:est)?)\.?` -const streetPattern = String.raw`\d{1,4} [\w\s]{1,50}(?:\b${streetSuffixPattern}\b)\.?(?:[ ]${directionPattern})?` +const zipPattern = String.raw`\d{5}(?:-\d{4})?`; +const cityPattern = String.raw`(?:[A-Z][a-z.-]+[ ]?){0,70}`; +const statePattern = String.raw`Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New[ ]Hampshire|New[ ]Jersey|New[ ]Mexico|New[ ]York|North[ ]Carolina|North[ ]Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode[ ]Island|South[ ]Carolina|South[ ]Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West[ ]Virginia|Wisconsin|Wyoming`; +const stateAbbrvPattern = String.raw`AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY`; +const cityStateZipPattern = String.raw`${cityPattern},\s*(?:${statePattern}|${stateAbbrvPattern}),?\s*${zipPattern}`; +const streetSuffixPattern = + String.raw`Alley|Allee|Ally|Aly|Annex|Anex|Annx|Anx|Arcade|Arc|Avenue|Av|Ave|Aven|Avenu|Avn|Avnue|Bayou` + + `|Bayoo|Byu|Beach|Bch|Bend|Bnd|Bluff|Bluf|Blf|Bluffs|Blfs|Bottom|Bot|Bottm|Btm|Boulevard|Boul` + + `|Boulv|Blvd|Branch|Brnch|Br|Bridge|Brdge|Brg|Brook|Brk|Brooks|Brks|Burg|Bg|Burgs|Bgs|Bypass` + + `|Bypa|Bypas|Byps|Byp|Camp|Cmp|Cp|Canyon|Canyn|Cnyn|Cyn|Cape|Cpe|Causeway|Causwa|Cswy|Center` + + `|Cen|Cent|Centr|Centre|Cnter|Cntr|Ctr|Centers|Ctrs|Circle|Circ|Circl|Crcl|Crcle|Cir|Circles` + + `|Cirs|Cliff|Clf|Cliffs|Clfs|Club|Clb|Common|Cmn|Commons|Cmns|Corner|Cor|Corners|Cors|Course` + + `|Crse|Court|Ct|Courts|Cts|Cove|Cv|Coves|Cvs|Creek|Crk|Crescent|Crsent|Crsnt|Cres|Crest|Crst` + + `|Crossing|Crssng|Xing|Crossroad|Xrd|Curve|Curv|Dale|Dl|Dam|Dm|Divide|Div|Dvd|Dv|Drive|Driv` + + `|Drv|Dr|Drives|Drs|Estate|Est|Estates|Ests|Expressway|Exp|Expr|Express|Expw|Expy|Extension` + + `|Extn|Extnsn|Ext|Extensions|Exts|Fall|Falls|Fls|Ferry|Frry|Fry|Field|Fld|Fields|Flds|Flat` + + `|Flt|Flats|Flts|Ford|Frd|Fords|Frds|Forest|Frst|Forge|Forg|Frg|Forges|Frgs|Fork|Frk|Forks` + + `|Frks|Fort|Frt|Ft|Freeway|Freewy|Frway|Frwy|Fwy|Garden|Gardn|Grden|Grdn|Gdn|Gardens|Gdns` + + `|Gateway|Gatewy|Gatway|Gtway|Gtwy|Glen|Gln|Glens|Glns|Green|Grn|Greens|Grns|Grove|Grov|Grv` + + `|Groves|Grvs|Harbor|Harb|Harbr|Hrbor|Hbr|Harbors|Hbrs|Haven|Hvn|Heights|Hts|Highway|Highwy` + + `|Hiway|Hiwy|Hway|Hwy|Hill|Hl|Hills|Hls|Hollow|Hllw|Holw|Holws|Inlet|Inlt|Island|Is|Islands` + + `|Iss|Isle|Junction|Jction|Jctn|Junctn|Juncton|Jct|Junctions|Jcts|Key|Ky|Keys|Kys|Knoll|Knol` + + `|Knl|Knolls|Knls|Lake|Lk|Lakes|Lks|Land|Landing|Lndng|Lndg|Lane|Ln|Light|Lgt|Lights|Lgts|Loaf` + + `|Lf|Lock|Lck|Locks|Lcks|Lodge|Ldge|Lodg|Ldg|Loop|Lp|Mall|Manor|Mnr|Manors|Mnrs|Meadow|Mdw` + + `|Meadows|Medows|Mdws|Mews|Mill|Ml|Mills|Mls|Mission|Msn|Motorway|Mtwy|Mount|Mt|Mountain|Mtn` + + `|Mountains|Mtns|Neck|Nck|Orchard|Orchrd|Orch|Oval|Ovl|Overpass|Opas|Park|Prk|Parks|Park|Parkway` + + `|Parkwy|Pkway|Pky|Pkwy|Parkways|Pkwys|Pass|Passage|Psge|Path|Pike|Pine|Pne|Pines|Pnes|Place|Pl` + + `|Plain|Pln|Plains|Plns|Plaza|Plza|Plz|Point|Pt|Points|Pts|Port|Prt|Ports|Prts|Prairie|Prr|Pr` + + `|Radial|Rad|Radiel|Radl|Ramp|Ranch|Rnch|Rnchs|Rapid|Rpd|Rapids|Rpds|Rest|Rst|Ridge|Rdge|Rdg` + + `|Ridges|Rdgs|River|Rvr|Rivr|Riv|Road|Rd|Roads|Rds|Route|Rte|Row|Rue|Run|Shoal|Shl|Shoals|Shls` + + `|Shore|Shr|Shores|Shrs|Skyway|Skwy|Spring|Spng|Sprng|Spg|Springs|Spgs|Spur|Square|Sqr|Sqre|Squ` + + `|Sq|Squares|Sqs|Station|Statn|Stn|Sta|Strasse|Stravenue|Strav|Straven|Stravn|Strvn|Strvnue|Stra` + + `|Stream|Streme|Strm|Street|Str|Strt|St|Streets|Sts|Summit|Sumit|Sumitt|Smt|Terrace|Terr|Ter` + + `|Throughway|Trwy|Trace|Trce|Track|Trak|Trk|Trks|Trafficway|Trfy|Trail|Trl|Trailer|Trlr|Tunnel` + + `|Tunl|Turnpike|Trnpk|Turnpk|Tpke|Underpass|Upas|Union|Un|Unions|Uns|Valley|Vally|Vlly|Vly` + + `|Valleys|Vlys|Via|Viaduct|Vdct|Viadct|Via|View|Vw|Views|Vws|Village|Vill|Villag|Villg|Vlg` + + `|Villages|Vlgs|Ville|Vl|Vista|Vist|Vst|Vsta|Vis|Walk|Wall|Way|Wy|Well|Wl|Wells|Wls`; +const directionPattern = String.raw`(?:[nN](?:orth)?|[eE](?:ast)?|[sS](?:outh)?|[wW](?:est)?)\.?`; +const streetPattern = String.raw`\d{1,4} [\w\s]{1,50}(?:\b${streetSuffixPattern}\b)\.?(?:[ ]${directionPattern})?`; const addressPattern = String.raw`(?:${streetPattern}\s${cityStateZipPattern})|(?:${streetPattern})|(?:${cityStateZipPattern})`; // Driver License patterns const dlPatternMap: Record = { - "AL": String.raw`\b\d{7}\b`, - "AZ": String.raw`\b[a-zA-Z][0-9]{8}\b|\b[0-9]{9}\b`, - "AR": String.raw`\b9[0-9]{8}\b`, - "CA": String.raw`\b[a-zA-Z][0-9]{7}\b`, - "CO": String.raw`\b[0-9]{2}-[0-9]{3}-[0-9]{4}\b`, - "FL": String.raw`\b[a-zA-Z][0-9]{12}\b|\b[a-zA-Z][0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{3}-[0-9]\b|\b[a-zA-Z]-[0-9]{3}-[0-9]{3}-[0-9]{3}-[0-9]{3}\b`, - "ID": String.raw`\b[a-zA-Z]{2}[0-9]{6}[a-zA-Z]\b`, - "IL": String.raw`\b[a-zA-Z][0-9]{11}\b|\b[a-zA-Z][0-9]{3}-[0-9]{4}-[0-9]{4}\b`, - "IN": String.raw`\b[0-9]{4}-[0-9]{2}-[0-9]{4}\b`, - "IA": String.raw`\b[0-9]{3}[a-zA-Z]{2}[0-9]{4}\b`, - "KS": String.raw`\b[a-zA-Z][0-9]{2}-[0-9]{2}-[0-9]{4}\b`, - "KY": String.raw`\b[a-zA-Z][0-9]{2}-[0-9]{3}-[0-9]{3}\b`, - "MA": String.raw`\bS[0-9]{8}\b|\bSA[0-9]{7}\b`, - "MI": String.raw`\b[a-zA-Z][ ][0-9]{3}[ ][0-9]{3}[ ][0-9]{3}[ ][0-9]{3}\b`, - "MN": String.raw`\b[a-zA-Z][0-9]{3}-[0-9]{3}-[0-9]{3}-[0-9]{3}\b`, - "MS": String.raw`\b[0-9]{3}-[0-9]{2}-[0-9]{4}\b`, - "MT": String.raw`\b(?:(?:[0][1-9]|[1][0-2])[0-9]{3}(?:[1-9][0-9]{3})41(?:[0][1-9]|[1][0-9]|[2][0-9]|[3][0-1]))\b`, - "NV": String.raw`\b[0-9]{10}\b|\b[0-9]{12}\b`, - "NH": String.raw`\b(?:[0][1-9]|[1][0-2])[a-zA-Z]{3}[0-9]{2}(?:0[1-9]|[1-2][0-9]|3[0-1])[0-9]\b`, - "NJ": String.raw`\b[a-zA-Z][0-9]{4} [0-9]{5} [0-9]{5}\b|\b[a-zA-Z][0-9]{14}\b`, - "NY": String.raw`\b[0-9]{3} [0-9]{3} [0-9]{3}\b`, - "ND": String.raw`\b[a-zA-Z]{3}-[0-9]{2}-[0-9]{4}\b|\b[a-zA-Z][0-9]{9}\b`, - "OH": String.raw`\b[a-zA-Z]{2}[0-9]{6}\b`, - "PA": String.raw`\b[0-9]{2} [0-9]{3} [0-9]{3}\b`, - "RI": String.raw`\b[1-9]{2}[0-9]{5}\b`, - "SD": String.raw`\b[0-9]{8}\b`, - "VT": String.raw`\b[0-9]{7}[a-zA-Z]\b`, - "WA": String.raw`\b[a-zA-Z\*]{5}[a-zA-Z]{2}[0-9]{3}[a-zA-Z0-9]{2}\b|\bWDL[a-zA-Z0-9]{9}\b`, - "WV": String.raw`\b[a-zA-Z][0-9]{6}\b`, - "WI": String.raw`\b[a-zA-Z][0-9]{3}-[0-9]{4}-[0-9]{4}-[0-9]{2}\b|\b[a-zA-Z][0-9]{13}\b`, - "WY": String.raw`\b[0-9]{6}-[0-9]{3}\b`, -} -const driverLicensePattern = Object.values(dlPatternMap).join("|") + AL: String.raw`\b\d{7}\b`, + AZ: String.raw`\b[a-zA-Z][0-9]{8}\b|\b[0-9]{9}\b`, + AR: String.raw`\b9[0-9]{8}\b`, + CA: String.raw`\b[a-zA-Z][0-9]{7}\b`, + CO: String.raw`\b[0-9]{2}-[0-9]{3}-[0-9]{4}\b`, + FL: String.raw`\b[a-zA-Z][0-9]{12}\b|\b[a-zA-Z][0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{3}-[0-9]\b|\b[a-zA-Z]-[0-9]{3}-[0-9]{3}-[0-9]{3}-[0-9]{3}\b`, + ID: String.raw`\b[a-zA-Z]{2}[0-9]{6}[a-zA-Z]\b`, + IL: String.raw`\b[a-zA-Z][0-9]{11}\b|\b[a-zA-Z][0-9]{3}-[0-9]{4}-[0-9]{4}\b`, + IN: String.raw`\b[0-9]{4}-[0-9]{2}-[0-9]{4}\b`, + IA: String.raw`\b[0-9]{3}[a-zA-Z]{2}[0-9]{4}\b`, + KS: String.raw`\b[a-zA-Z][0-9]{2}-[0-9]{2}-[0-9]{4}\b`, + KY: String.raw`\b[a-zA-Z][0-9]{2}-[0-9]{3}-[0-9]{3}\b`, + MA: String.raw`\bS[0-9]{8}\b|\bSA[0-9]{7}\b`, + MI: String.raw`\b[a-zA-Z][ ][0-9]{3}[ ][0-9]{3}[ ][0-9]{3}[ ][0-9]{3}\b`, + MN: String.raw`\b[a-zA-Z][0-9]{3}-[0-9]{3}-[0-9]{3}-[0-9]{3}\b`, + MS: String.raw`\b[0-9]{3}-[0-9]{2}-[0-9]{4}\b`, + MT: String.raw`\b(?:(?:[0][1-9]|[1][0-2])[0-9]{3}(?:[1-9][0-9]{3})41(?:[0][1-9]|[1][0-9]|[2][0-9]|[3][0-1]))\b`, + NV: String.raw`\b[0-9]{10}\b|\b[0-9]{12}\b`, + NH: String.raw`\b(?:[0][1-9]|[1][0-2])[a-zA-Z]{3}[0-9]{2}(?:0[1-9]|[1-2][0-9]|3[0-1])[0-9]\b`, + NJ: String.raw`\b[a-zA-Z][0-9]{4} [0-9]{5} [0-9]{5}\b|\b[a-zA-Z][0-9]{14}\b`, + NY: String.raw`\b[0-9]{3} [0-9]{3} [0-9]{3}\b`, + ND: String.raw`\b[a-zA-Z]{3}-[0-9]{2}-[0-9]{4}\b|\b[a-zA-Z][0-9]{9}\b`, + OH: String.raw`\b[a-zA-Z]{2}[0-9]{6}\b`, + PA: String.raw`\b[0-9]{2} [0-9]{3} [0-9]{3}\b`, + RI: String.raw`\b[1-9]{2}[0-9]{5}\b`, + SD: String.raw`\b[0-9]{8}\b`, + VT: String.raw`\b[0-9]{7}[a-zA-Z]\b`, + WA: String.raw`\b[a-zA-Z\*]{5}[a-zA-Z]{2}[0-9]{3}[a-zA-Z0-9]{2}\b|\bWDL[a-zA-Z0-9]{9}\b`, + WV: String.raw`\b[a-zA-Z][0-9]{6}\b`, + WI: String.raw`\b[a-zA-Z][0-9]{3}-[0-9]{4}-[0-9]{4}-[0-9]{2}\b|\b[a-zA-Z][0-9]{13}\b`, + WY: String.raw`\b[0-9]{6}-[0-9]{3}\b`, +}; +const driverLicensePattern = Object.values(dlPatternMap).join("|"); // Geographic Coordinate patterns -const latitudePattern = String.raw`[-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)`; -const longitudePattern = String.raw`[-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)` -const coordinatePattern = String.raw`\b${latitudePattern}\s*,\s*${longitudePattern}\b` +const latitudePattern = String.raw`[-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)`; +const longitudePattern = String.raw`[-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)`; +const coordinatePattern = String.raw`\b${latitudePattern}\s*,\s*${longitudePattern}\b`; // Birthday patterns (min: 1900, max: 2099) -const yyyyMmDd = String.raw`\b(?:19\d{2}|20[01][0-9]|20\d{2})[-/.](?:0[1-9]|1[012])[-/.](?:0[1-9]|[12][0-9]|3[01])\b` -const mmDdYyyy = String.raw`\b(?:0[1-9]|1[012])[-/.](?:0[1-9]|[12][0-9]|3[01])[-/.](?:19\d{2}|20[01][0-9]|20\d{2})\b` -const ddMmYyyy = String.raw`\b(?:0[1-9]|[12][0-9]|3[01])[-/.](?:0[1-9]|1[012])[-/.](?:19\d{2}|20[01][0-9]|20\d{2})\b` -const dobPattern = String.raw`${yyyyMmDd}|${mmDdYyyy}|${ddMmYyyy}` +const yyyyMmDd = String.raw`\b(?:19\d{2}|20[01][0-9]|20\d{2})[-/.](?:0[1-9]|1[012])[-/.](?:0[1-9]|[12][0-9]|3[01])\b`; +const mmDdYyyy = String.raw`\b(?:0[1-9]|1[012])[-/.](?:0[1-9]|[12][0-9]|3[01])[-/.](?:19\d{2}|20[01][0-9]|20\d{2})\b`; +const ddMmYyyy = String.raw`\b(?:0[1-9]|[12][0-9]|3[01])[-/.](?:0[1-9]|1[012])[-/.](?:19\d{2}|20[01][0-9]|20\d{2})\b`; +const dobPattern = String.raw`${yyyyMmDd}|${mmDdYyyy}|${ddMmYyyy}`; // IP address patterns -const ipV4Pattern = String.raw`\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b` +const ipV4Pattern = String.raw`\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b`; // Credit card patterns -const americanExpressPattern = String.raw`\b3[47][0-9]{13}\b|\b3[47][0-9]{2}-[0-9]{6}-[0-9]{5}\b|\b3[47][0-9]{2}[ ][0-9]{6}[ ][0-9]{5}\b` -const visaPattern = String.raw`\b4[0-9]{12}(?:[0-9]{3})?\b|\b4[0-9]{3}-[0-9]{4}-[0-9]{4}-[0-9]{4}\b|\b4[0-9]{3}[ ][0-9]{4}[ ][0-9]{4}[ ][0-9]{4}\b` -const mastercardPattern = String.raw`\b5[1-5][0-9]{14}\b|\b(?:222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[0-1]\d|2720)[0-9]{12}\b` -const discoverPattern = String.raw`\b6(?:011\d{12,15}|5\d{14,17}|4[4-9]\d{13,16}|22(?:1(?:2[6-9]|[3-9]\d)|[2-8]\d{2}|9(?:[01]\d|2[0-5]))\d{10,13})\b` -const jcbPattern = String.raw`\b(?:2131|1800|35[0-9]{3})[0-9]{11}\b` -const creditCardPattern = String.raw`${americanExpressPattern}|${visaPattern}|${mastercardPattern}|${discoverPattern}|${jcbPattern}` - +const americanExpressPattern = String.raw`\b3[47][0-9]{13}\b|\b3[47][0-9]{2}-[0-9]{6}-[0-9]{5}\b|\b3[47][0-9]{2}[ ][0-9]{6}[ ][0-9]{5}\b`; +const visaPattern = String.raw`\b4[0-9]{12}(?:[0-9]{3})?\b|\b4[0-9]{3}-[0-9]{4}-[0-9]{4}-[0-9]{4}\b|\b4[0-9]{3}[ ][0-9]{4}[ ][0-9]{4}[ ][0-9]{4}\b`; +const mastercardPattern = String.raw`\b5[1-5][0-9]{14}\b|\b(?:222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[0-1]\d|2720)[0-9]{12}\b`; +const discoverPattern = String.raw`\b6(?:011\d{12,15}|5\d{14,17}|4[4-9]\d{13,16}|22(?:1(?:2[6-9]|[3-9]\d)|[2-8]\d{2}|9(?:[01]\d|2[0-5]))\d{10,13})\b`; +const jcbPattern = String.raw`\b(?:2131|1800|35[0-9]{3})[0-9]{11}\b`; +const creditCardPattern = String.raw`${americanExpressPattern}|${visaPattern}|${mastercardPattern}|${discoverPattern}|${jcbPattern}`; // Email patterns -const emailPattern = String.raw`(?:[a-z0-9!#$%&'*+/=?^_` + "`" + String.raw`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_` + "`" + String.raw`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])` +const emailPattern = + String.raw`(?:[a-z0-9!#$%&'*+/=?^_` + + "`" + + String.raw`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_` + + "`" + + String.raw`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])`; // SSN patterns -const ssnPattern = String.raw`\b(?!000|666|333|9[0-9]{2})[0-9]{3}[- ]?(?!00)[0-9]{2}[- ]?(?!0000)[0-9]{4}\b` +const ssnPattern = String.raw`\b(?!000|666|333|9[0-9]{2})[0-9]{3}[- ]?(?!00)[0-9]{2}[- ]?(?!0000)[0-9]{4}\b`; // Phone number patterns -const phoneNumberPattern = String.raw`\b(?:(?:(?([ [DataClass.ADDRESS, ADDRESS_REGEXP], @@ -12,7 +23,7 @@ const DATA_CLASS_REGEX_MAP = new Map([ [DataClass.PHONE_NUMBER, PHONE_NUMBER_REGEXP], [DataClass.SSN, SSN_REGEXP], [DataClass.VIN, VIN_REGEXP], -]) +]); export class ScannerService { static scan = (text: string) => { @@ -22,7 +33,7 @@ export class ScannerService { if (matches?.length > 0) { res[dataClass] = matches; } - }) + }); return res; - } + }; } diff --git a/backend/src/types.ts b/backend/src/types.ts index fab39169..903e5819 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -1,53 +1,53 @@ -import { RestMethod } from "./enums" +import { RestMethod } from "./enums"; export interface Meta { - incoming: boolean - source: string - sourcePort: string - destination: string - destinationPort: string - environment: string + incoming: boolean; + source: string; + sourcePort: string; + destination: string; + destinationPort: string; + environment: string; } export interface Parameter { - name: string - value: string + name: string; + value: string; } export interface Header { - name: string - value: string + name: string; + value: string; } export interface Url { - host: string - path: string - parameters: Parameter[] + host: string; + path: string; + parameters: Parameter[]; } export interface Request { - url: Url - headers: Header[] - body: string - method: RestMethod + url: Url; + headers: Header[]; + body: string; + method: RestMethod; } export interface Response { - status: number - headers: Header[] - body: string + status: number; + headers: Header[]; + body: string; } export interface TraceParams { - request: Request - response: Response - meta: Meta + request: Request; + response: Response; + meta: Meta; } export interface GetEndpointParams { - environment?: string - host?: string - riskScore?: string - offset?: number - limit?: number + environment?: string; + host?: string; + riskScore?: string; + offset?: number; + limit?: number; } diff --git a/backend/yarn.lock b/backend/yarn.lock index fafcc40d..4e1fcaf6 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -889,6 +889,11 @@ postgres-interval@^1.1.0: dependencies: xtend "^4.0.0" +prettier@^2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + proxy-addr@~2.0.7: version "2.0.7" resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.7.tgz#f19fe69ceab311eeb94b42e70e8c2070f9ba1025"