Skip to content

Commit cc9eac8

Browse files
authored
Merge pull request #134 from VeloraDEX/feature/DVOPS-310
DVOPS-310: Secrets detection pre-commit
2 parents 2019396 + 369c21b commit cc9eac8

File tree

10 files changed

+375
-601
lines changed

10 files changed

+375
-601
lines changed

.github/workflows/ci.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
on: push
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
node: ['22.x']
10+
name: Node ${{ matrix.node }} sample
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup node
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: ${{ matrix.node }}
19+
20+
- name: Install Dependencies
21+
run: yarn
22+
23+
- name: Run Trivy vulnerability scanner in fs mode
24+
uses: aquasecurity/trivy-action@0.29.0
25+
with:
26+
scan-type: 'fs'
27+
scan-ref: '.'
28+
ignore-unfixed: true
29+
severity: 'CRITICAL'
30+
exit-code: 0
31+
hide-progress: true
32+
scanners: vuln,secret,misconfig
33+
output: 'trivy-scan-results'
34+
35+
- name: Upload Trivy report as a Github artifact
36+
if: always()
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: trivy-report
40+
path: '${{ github.workspace }}/trivy-scan-results'
41+
retention-days: 7

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ yarn-error.log
77

88
dist
99

10-
.env
10+
.env*
11+
!.env.example
12+
!.env.sample
13+
14+
.husky/.git-secrets-installed
1115

1216
TODO
1317

.husky/pre-commit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
if ! command -v git-secrets &> /dev/null
2+
then
3+
echo "git-secrets is not installed. Please run 'brew install git-secrets' or visit https://github.com/awslabs/git-secrets#installing-git-secrets"
4+
exit 1
5+
fi
6+
7+
8+
HOOK_FLAG=".husky/.git-secrets-installed"
9+
if [[ ! -f "$HOOK_FLAG" ]]; then
10+
git-secrets --register-aws > /dev/null
11+
git secrets --add -- 'ghp_[A-Za-z0-9_]\{36\}'
12+
git secrets --add -- 'github_pat_[A-Za-z0-9_]\{36\}'
13+
git secrets --add -- 'xox[apb]-[0-9]\{12\}-[0-9]\{12\}-[A-Za-z0-9]\{24\}'
14+
git secrets --add -- 'sk_live_[A-Za-z0-9]\{24\}'
15+
git secrets --add -- 'pk_live_[A-Za-z0-9]\{24\}'
16+
git secrets --add -- 'AIza[0-9A-Za-z_-]\{35\}'
17+
git secrets --add -- '^[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}$'
18+
git secrets --add -- '[A-Za-z0-9_-]\{20,\}\.[A-Za-z0-9_-]\{20,\}\.[A-Za-z0-9_-]\{20,\}'
19+
git secrets --add -- 'postgres:\/\/[A-Za-z0-9@:\-_.\/?%=+]+'
20+
git secrets --add -- 'BEGIN'
21+
touch "$HOOK_FLAG"
22+
fi
23+
24+
echo "🔍 Running git-secrets..."
25+
git-secrets --pre_commit_hook -- "$@"

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# compile typescript to ./dist
2-
FROM node:16-alpine AS tsc
2+
FROM node:22-alpine AS tsc
33
WORKDIR /app
44
COPY ["package*.json", "tsconfig.json", "yarn.lock", "./"]
55
RUN yarn install
66
COPY . ./
77
RUN yarn build
88

99
# install production only dependencies
10-
FROM node:16-alpine as yarn-prod
10+
FROM node:22-alpine AS yarn-prod
1111
WORKDIR /app
1212
COPY --from=tsc /app/package*.json ./
1313
COPY --from=tsc /app/yarn.lock ./
1414
COPY --from=tsc /app/dist ./
1515
RUN yarn install --production
1616

1717
# copy only production artifacts (get rid of yarn cache)
18-
FROM node:16-alpine as image
18+
FROM node:22-alpine AS image
1919
RUN apk --no-cache add dumb-init curl && rm -rf /var/cache/apk/*
2020
WORKDIR /app
2121
COPY --from=yarn-prod /app ./

Dockerfile.grp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# compile typescript to ./dist
2-
FROM node:16-alpine AS tsc
2+
FROM node:22-alpine AS tsc
33
WORKDIR /app
44
COPY ["package*.json", "tsconfig.json", "yarn.lock", "./"]
55
RUN yarn install
66
COPY . ./
77
RUN yarn build:grp
88

99
# install production only dependencies
10-
FROM node:16-alpine as yarn-prod
10+
FROM node:22-alpine AS yarn-prod
1111
WORKDIR /app
1212
COPY --from=tsc /app/package*.json ./
1313
COPY --from=tsc /app/yarn.lock ./
@@ -17,7 +17,7 @@ RUN yarn install --production
1717
RUN ./node_modules/.bin/patch-package
1818

1919
# copy only production artifacts (get rid of yarn cache)
20-
FROM node:16-alpine as image
20+
FROM node:22-alpine AS image
2121
WORKDIR /app
2222
COPY --from=yarn-prod /app ./
2323
CMD ["yarn", "gas-refund:prod:compute-gas-refund-save-db"]

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"gas-refund:computeDistributionFilesAndPersistIPFS": "patch-package && NODE_ENV=development ts-node scripts/gas-refund-program/distribution/computeDistributionFilesAndPersistIPFS",
2020
"migrate:up": "source .env && DATABASE_URL=$DATABASE_URL npx sequelize-cli db:migrate # <- executes any new migrations that are not in sequalize meta table yet, sorted alphabetically",
2121
"migrate:undo": "source .env && DATABASE_URL=$DATABASE_URL npx sequelize-cli db:migrate:undo # <- undoes the last migration from sequalize meta table, sorted alphabetically",
22-
"test": "jest"
22+
"test": "jest",
23+
"prepare": "husky"
2324
},
2425
"husky": {
2526
"hooks": {
@@ -41,7 +42,7 @@
4142
"@types/node": "14.14.41",
4243
"@types/stoppable": "1.1.1",
4344
"@types/validator": "13.6.6",
44-
"husky": "7.0.4",
45+
"husky": "^9.1.7",
4546
"jest": "^27.5.1",
4647
"jest-chance": "^0.1.11",
4748
"mkdirp": "^3.0.1",
@@ -79,7 +80,7 @@
7980
"log4js": "6.3.0",
8081
"merkletreejs": "^0.2.31",
8182
"moment": "2.29.1",
82-
"newrelic": "11.15.0",
83+
"newrelic": "12.24.0",
8384
"p-limit": "^3.1.0",
8485
"p-memoize": "^4.0.4",
8586
"parse-duration": "1.0.2",

src/lib/access-log.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Request, Response } from 'express';
2+
import { connectLogger } from 'log4js';
3+
4+
import { getRemoteAddress } from './remote-address';
5+
import { ACCESS_LOG_CATEGORY } from './log4js';
6+
7+
const logger = global.LOGGER(ACCESS_LOG_CATEGORY, true);
8+
9+
export default function AccessLogMiddleware() {
10+
return connectLogger(logger, {
11+
level: 'auto',
12+
13+
format: (req: Request, res: Response, format: (str: string) => string) => {
14+
const baseLog = `${getRemoteAddress(req)} :hostname HTTP/:http-version :method ":url" :status :content-length - :response-timems`;
15+
return format(baseLog);
16+
},
17+
});
18+
}

src/lib/log4js.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function calculateCategory() {
2727
return parsed?.fileName.split('.')[0].split(path.sep).join('.');
2828
}
2929

30+
export const ACCESS_LOG_CATEGORY = 'ACCESS-LOG';
31+
3032
const configuration: log4js.Configuration = {
3133
appenders: {
3234
console: {
@@ -45,7 +47,7 @@ const configuration: log4js.Configuration = {
4547
level: process.env['LOGGER_LEVEL'] || isDev ? 'trace' : 'info',
4648
enableCallStack: isDev,
4749
},
48-
ACCESS_LOG_CATEGORY: {
50+
[ACCESS_LOG_CATEGORY]: {
4951
appenders: ['console'],
5052
level: 'info',
5153
},

src/lib/middleware.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as express from 'express';
22
import * as parser from 'body-parser';
3-
import * as compression from 'compression';
4-
import * as cookie from 'cookie-parser';
3+
import AccessLogMiddleware from './access-log';
54

65
const logger = global.LOGGER();
76

@@ -40,6 +39,9 @@ export default class Middleware {
4039
app.use(parser.json({ strict: false }));
4140
app.use(parser.text());
4241

42+
// generates access log message
43+
app.use(AccessLogMiddleware());
44+
4345
app.get('/robots.txt', function (req, res) {
4446
res.type('text/plain');
4547
res.send(`

0 commit comments

Comments
 (0)