Skip to content

Update security + dependencies #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e2cfb30
chore(deps): update timoa/nodejs-encryption-api-example digest to 509…
renovate-bot Apr 15, 2022
b36bdf2
chore(deps): update github/codeql-action action to v2
renovate-bot Apr 15, 2022
f7d4a1b
Merge pull request #88 from timoa/fix/deps/github-codeql-action-2.x
timoa Apr 16, 2022
dd2a836
chore(deps): update actions/setup-node action to v3.1.0
renovate-bot Apr 16, 2022
9430555
chore(cicd): update the CodeQL Analysis workflow
timoa Apr 17, 2022
e54beb4
chore(cicd): add support to Reviewdog + Hadolint
timoa Apr 18, 2022
4df3cf5
fix(docs): fix duplicated lines badge link
timoa Apr 18, 2022
5002369
chore(docs): add the GitHub release badge
timoa Apr 18, 2022
15b1750
chore(docs): minor fix
timoa Apr 18, 2022
bfd55dd
chore(deps): update reviewdog/action-hadolint action to v1.0.4
renovate-bot Apr 18, 2022
60c3e15
chore(deps): update github/codeql-action action to v2.1.8
renovate-bot Apr 18, 2022
81e0b91
chore(deps): update reviewdog/action-hadolint action to v1.32.0
renovate-bot Apr 18, 2022
89e7d25
chore(deps): pin actions/checkout action to v
renovate-bot Apr 19, 2022
56f0fc2
Merge pull request #90 from timoa/fix/deps/pin-dependencies
timoa Apr 19, 2022
5e380a3
chore(release): add the Git URL to the .releaserc file
timoa Apr 20, 2022
330f581
chore(deps): update dependency eslint-plugin-import to v2.26.0
renovate-bot Apr 20, 2022
64217ea
chore(deps): update docker/metadata-action action to v3.7.0
renovate-bot Apr 21, 2022
185c03d
chore(deps): update actions/checkout digest to 2541b12
renovate-bot Apr 21, 2022
75995c5
chore(deps): update mongo digest to 7a43a1b
renovate-bot Apr 22, 2022
7fc1028
chore(deps): update actions/setup-node action to v3.1.1
renovate-bot Apr 22, 2022
e912a3d
chore(deps): update dependency eslint to v8.13.0
renovate-bot Apr 26, 2022
6512d31
fix(deps): update dependency @snyk/protect to v1.902.0
renovate-bot Apr 26, 2022
9793e8b
chore(deps): update mongo digest to 958b874
renovate-bot Apr 27, 2022
f733361
fix(deps): update dependency @snyk/protect to v1.903.0
renovate-bot Apr 27, 2022
9c7bca8
fix(deps): update dependency @snyk/protect to v1.904.0
renovate-bot Apr 27, 2022
b440e32
chore(deps): update github/codeql-action action to v2.1.9
renovate-bot Apr 27, 2022
da0fdf8
chore(deps): update node.js to v16.15.0
renovate-bot Apr 28, 2022
bbe125c
fix(deps): update dependency @snyk/protect to v1.905.0
renovate-bot Apr 28, 2022
eca8c04
fix(deps): update dependency @snyk/protect to v1.906.0
renovate-bot Apr 29, 2022
fbc5ea1
chore(deps): update actions/checkout action to v3.0.1
renovate-bot Apr 29, 2022
92cd9ff
chore(deps): update mongo digest to 981c74b
renovate-bot Apr 30, 2022
7681384
fix(deps): update dependency @snyk/protect to v1.907.0
renovate-bot May 2, 2022
61392c2
chore(docs): add the CODEOWNERS file
timoa May 2, 2022
3a7f31d
chore(deps): update reviewdog/action-hadolint action to v1.32.1
renovate-bot May 2, 2022
89a7c41
feat(helmet): add Helmet support to secure HTTP headers
timoa May 4, 2022
e8a0ed0
Merge pull request #92 from timoa/feature/fastify-helmet
timoa May 4, 2022
f2f98b5
chore(docs): update README with latest changes
timoa May 4, 2022
129d01a
chore(docs): fix missing updates
timoa May 4, 2022
1c48afa
fix(deps): update dependency @snyk/protect to v1.908.0
renovate-bot May 4, 2022
ebef95e
chore(cicd): add ESLint check for the Pull Requests
timoa May 6, 2022
ab85642
chore(cicd): add better labels for the jobs
timoa May 6, 2022
2f35f57
fix(cicd): fix nodejs pipeline
timoa May 6, 2022
33079bc
chore(cicd): minor fix
timoa May 6, 2022
5f33c13
chore(deps): update reviewdog/action-eslint action to v1.0.1
renovate-bot May 6, 2022
f253ef7
chore(cicd): add missing Github Token fro Reviewdog
timoa May 6, 2022
053840e
chore(deps): update actions/checkout action to v3.0.2
renovate-bot May 6, 2022
a6c8eac
chore(deps): update reviewdog/action-eslint action to v1.17.0
renovate-bot May 6, 2022
ee72c98
chore(deps): update reviewdog/action-hadolint action to v1.33.0
renovate-bot May 6, 2022
d3f91c3
fix(deps): update dependency @snyk/protect to v1.910.0
renovate-bot May 7, 2022
4660b66
chore(deps): update dependency eslint to v8.14.0
renovate-bot May 7, 2022
5c796e1
fix(deps): update dependency @snyk/protect to v1.912.0
renovate-bot May 7, 2022
1a1a25f
chore(deps): update github/codeql-action action to v2.1.10
renovate-bot May 10, 2022
508f84e
chore(deps): update dependency acorn to v8.7.1
renovate-bot May 11, 2022
ae8d493
chore(deps): update github/codeql-action digest to 2f58583
renovate-bot May 11, 2022
044a8fe
chore(deps): update mongo digest to 82a55eb
renovate-bot May 11, 2022
884c1a5
fix(deps): update dependency @snyk/protect to v1.913.0
renovate-bot May 11, 2022
9ea4b34
fix(deps): update dependency fastify-swagger to v5.2.0
renovate-bot May 12, 2022
fed6f25
fix(deps): update dependency @snyk/protect to v1.914.0
renovate-bot May 12, 2022
dbae6cd
chore(deps): update docker/setup-buildx-action action to v1.7.0
renovate-bot May 13, 2022
1ead7c8
chore(deps): update docker/metadata-action action to v3.8.0
renovate-bot May 13, 2022
f2ad318
fix(deps): update dependency fastify to v3.29.0
renovate-bot May 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@timoa
33 changes: 33 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Code Review

on: [pull_request]

jobs:

# -- ESLINT -----------------------------------------------------------------
eslint:
name: ESLint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Run ESLint
uses: reviewdog/action-eslint@d3395027ea2cfc5cf8f460b1ea939b6c86fea656 # tag=v1.17.0
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# -- DOCKER -----------------------------------------------------------------
hadolint:
name: Hadolint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Run hadolint
uses: reviewdog/action-hadolint@55be5d2c4b0b80d439247b128a9ded3747f92a29 # tag=v1.33.0
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95 changes: 51 additions & 44 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
name: "CodeQL"
name: "CodeQL analysis"

on:
push:
branches: [master, ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
branches: [main]
schedule:
- cron: '0 7 * * 0'
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '30 1 * * 0'

jobs:
analyze:
name: Analyze
CodeQL-Build:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest

permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@e2cc7cc006b87d43538b16d71752753e7b85224d # tag=v1.1.8
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@e2cc7cc006b87d43538b16d71752753e7b85224d # tag=v1.1.8

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@e2cc7cc006b87d43538b16d71752753e7b85224d # tag=v1.1.8
- name: Checkout repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
27 changes: 16 additions & 11 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:

# -- TESTS ------------------------------------------------------------------
tests:
name: Tests
runs-on: ubuntu-latest

strategy:
Expand All @@ -15,10 +16,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3
uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3.1.1
with:
node-version: ${{ matrix.node }}
check-latest: true
Expand All @@ -43,12 +44,13 @@ jobs:

# -- SONARCLOUD -------------------------------------------------------------
code-quality:
name: Code Quality
runs-on: ubuntu-latest
needs: tests

steps:
- name: Checkout
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Download Code Coverage
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
Expand Down Expand Up @@ -93,14 +95,15 @@ jobs:

# -- SAST SCAN --------------------------------------------------------------
code-security:
name: Code Security
runs-on: ubuntu-latest
needs: tests
# Skip any PR created by dependabot to avoid permission issues
if: (github.actor != 'dependabot[bot]')

steps:
- name: Checkout
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 # tag=v3
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Perform Scan
uses: ShiftLeftSecurity/scan-action@master
Expand All @@ -115,8 +118,9 @@ jobs:
name: reports
path: reports

# -- RELEASE ----------------------------------------------------------------
release:
# -- PRE-RELEASE ------------------------------------------------------------
pre-release:
name: Prepare Release
runs-on: ubuntu-latest
needs:
- code-quality
Expand All @@ -125,7 +129,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 # tag=v3
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
Expand All @@ -134,17 +138,18 @@ jobs:

# -- BUILD ------------------------------------------------------------------
build:
name: Build & Release
runs-on: ubuntu-latest
needs: release
needs: pre-release
if: github.ref == 'refs/heads/master'

steps:
- name: Checkout
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Docker meta
id: meta
uses: docker/metadata-action@e5622373a38e60fb6d795a4421e56882f2d7a681 # tag=v3.6.2
uses: docker/metadata-action@b2391d37b4157fa4aa2e118d643f417910ff3242 # tag=v3.8.0
with:
images: ${{ github.repository }}
tags: |
Expand All @@ -161,7 +166,7 @@ jobs:
uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # tag=v1.2.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # tag=v1.6.0
uses: docker/setup-buildx-action@f211e3e9ded2d9377c8cadc4489a4e38014bc4c9 # tag=v1.7.0

- name: Login to DockerHub
uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 # tag=v1.14.1
Expand Down
1 change: 1 addition & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"repositoryUrl": "https://github.com/timoa/nodejs-encryption-api-example.git",
"branches": [
"master",
"develop"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.14.2-alpine3.15@sha256:28bed508446db2ee028d08e76fb47b935defa26a84986ca050d2596ea67fd506
FROM node:16.15.0-alpine3.15@sha256:1a9a71ea86aad332aa7740316d4111ee1bd4e890df47d3b5eff3e5bded3b3d10
ARG appPort=3000
# ARG microScannerToken

Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Encryption API endpoints with Node.js

[![Latest Release][release-badge]][release-url]
[![Build Status][github-badge]][github-url]
[![Docker Pulls][docker-badge]][docker-url]

[![Quality Gate Status][sonarcloud-status-badge]][sonarcloud-url]
[![Security Rating][sonarcloud-security-badge]][sonarcloud-url]
[![Maintainability Rating][sonarcloud-maintainability-badge]][sonarcloud-url]
Expand All @@ -21,17 +23,18 @@ The idea with this example is to test how to store encrypted data under a datast

## Features

- API storing endpoint that encrypts data with the provided key and stores it into a MongoDB collection (AES-256-CBC encryption)
- API storing endpoint that encrypts data with the provided key and stores it into a MongoDB collection (AES-256-GCM encryption)
- API retrieval endpoint that decrypts data with the provided key and returns the data
- AES-256-CBC encryption that uses a random Initialization Vector (IV)
- IV stored with the encrypted data (separated by a `:` character)
- AES-256-GCM encryption that uses a random Initialization Vector (IV) and Auth TAG
- IV and Auth TAG stored with the encrypted data (separated by a `:` character)
- Logs with correlation ID
- Hardening of the HTTP Headers with Helmet
- MongoDB as a data store (using Mongoose)
- Swagger support for API specifications/documentation (WIP)
- Health check endpoint to check if the app is still alive
- Dockerfile to generate the Docker image
- Docker Compose file to launch the API and MongoDB official Docker images
- Build, test and deploy to Docker Hub with Travis CI
- Build, test and deploy to Docker Hub with GitHub Actions
- SonarQube code quality check (SonarCloud)
- Unit tests and functional tests
- Postman collection and environment
Expand Down Expand Up @@ -247,6 +250,8 @@ This will return an array of results:
[postman-run-button]: https://run.pstmn.io/button.svg
[postman-run-url]: https://app.getpostman.com/run-collection/e34aee6688c0937c6643
[sonarcloud]: https://sonarcloud.io/about
[release-badge]: https://img.shields.io/github/v/release/timoa/nodejs-encryption-api-example?logoColor=orange
[release-url]: https://github.com/timoa/nodejs-encryption-api-example/releases
[github-badge]: https://github.com/timoa/nodejs-encryption-api-example/workflows/Build/badge.svg
[github-url]: https://github.com/timoa/nodejs-encryption-api-example/actions?query=workflow%3ABuild
[docker-badge]: https://img.shields.io/docker/pulls/timoa/nodejs-encryption-api-example.svg
Expand All @@ -258,4 +263,4 @@ This will return an array of results:
[sonarcloud-bugs-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=bugs
[sonarcloud-codesmells-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=code_smells
[sonarcloud-coverage-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=coverage
[sonarcloud-duplicated-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=duplicated_lines_densit
[sonarcloud-duplicated-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=duplicated_lines_density
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.3'

services:
api:
image: timoa/nodejs-encryption-api-example:latest@sha256:7348a5690fde457457ef0b171c992ae877af7e2084e6b384c096c85047188f78
image: timoa/nodejs-encryption-api-example:latest@sha256:509d3424b92adb94f06ceedaa8044aaffed0e99015ae4b8dcb95be0a82c0a7b2
environment:
- NODE_ENV=production
- NODE_HOST=0.0.0.0
Expand All @@ -17,7 +17,7 @@ services:
- mongo
mongo:
container_name: mongo
image: mongo@sha256:1e72fdd16fc769e5200dad77eff5b2316730d42473c281d8192872698e1f8689
image: mongo@sha256:82a55eb6d60997007ff390087d4e064218d477e9611a7becd78664a2ab490eff
volumes:
- ./data:/data/db
ports:
Expand Down
Loading