Skip to content

Commit 19e4311

Browse files
committed
HAWNG-395: Handle warnings and false-positives
* .gitleaks.toml * Provides an extension config which lists the false-positives that should be ignored * generate-.*\.sh * Fixes shellcheck warnings is assignments * nginx.sh * Removes pipefail setting as non-POSIX and since pipes not actually used in script then removed entirely * Replaces bash (-v) which POSIX compatible equivalent * ws-handler.ts * Checks the origin of the MessageEvent. Since the messages are expected from the cluster they should only comes from ${APP_HOST}/master so any other origin is not appropriate so should be ignored * .snyk * Exclude non-production files from snyk analysis
1 parent a781231 commit 19e4311

File tree

8 files changed

+61
-7
lines changed

8 files changed

+61
-7
lines changed

.gitleaks.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Title for the gitleaks configuration file.
2+
title = "Gitleaks Configuration"
3+
4+
# Extend the base (this) configuration. When you extend a configuration
5+
# the base rules take precedence over the extended rules. I.e., if there are
6+
# duplicate rules in both the base configuration and the extended configuration
7+
# the base rules will override the extended rules.
8+
# Another thing to know with extending configurations is you can chain together
9+
# multiple configuration files to a depth of 2. Allowlist arrays are appended
10+
# and can contain duplicates.
11+
# useDefault and path can NOT be used at the same time. Choose one.
12+
[extend]
13+
# useDefault will extend the base configuration with the default gitleaks config:
14+
# https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml
15+
useDefault = true
16+
17+
# This is a global allowlist which has a higher order of precedence than rule-specific allowlists.
18+
# If a commit listed in the `commits` field below is encountered then that commit will be skipped and no
19+
# secrets will be detected for said commit. The same logic applies for regexes and paths.
20+
[allowlist]
21+
description = "Ignore False-Positives"
22+
paths = [
23+
'''.yarn/.*''',
24+
'''packages/oauth/src/form/jwt-decode.test.ts'''
25+
]

.snyk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exclude:
2+
global:
3+
# Exclude all development webpack build config files
4+
- "webpack.config.dev.js"
5+
- "webpack.config.js"

deploy/script/generate-proxying.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ EOT
3232
}
3333

3434
kube_binary() {
35-
local k=$(command -v ${1} 2> /dev/null)
35+
local k
36+
k=$(command -v ${1} 2> /dev/null)
3637
if [ $? != 0 ]; then
3738
return
3839
fi

deploy/script/generate-serving.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ EOT
1818
}
1919

2020
kube_binary() {
21-
local k=$(command -v ${1} 2> /dev/null)
21+
local k
22+
k=$(command -v ${1} 2> /dev/null)
2223
if [ $? != 0 ]; then
2324
return
2425
fi

docker/nginx.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/sh
22

3-
# Fail on a single failed command in a pipeline (if supported)
4-
(set -o | grep -q pipefail) && set -o pipefail
5-
63
# Fail on error and undefined vars
74
set -eu
85

@@ -45,7 +42,7 @@ generate_nginx_gateway_conf() {
4542
' < $TEMPLATE > /etc/nginx/conf.d/nginx.conf
4643
}
4744

48-
if [ -v HAWTIO_ONLINE_RBAC_ACL ]; then
45+
if [ -n "${HAWTIO_ONLINE_RBAC_ACL+x}" ]; then
4946
echo Using RBAC NGINX configuration
5047
generate_nginx_gateway_conf
5148
elif [ "${HAWTIO_ONLINE_GATEWAY:-}" = "true" ]; then

packages/kubernetes-api/src/client/ws-handler.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,25 @@ export class WSHandlerImpl<T extends KubeObject> implements WSHandler<T> {
6565
ws.addEventListener('open', (event: Event) => self.onOpen(event))
6666

6767
log.debug("Adding WebSocket event handler for 'message'")
68-
ws.addEventListener('message', (event: MessageEvent) => self.onMessage(event))
68+
ws.addEventListener('message', (event: MessageEvent) => {
69+
if (!event.origin || event.origin.length === 0) {
70+
log.warn('Ignoring WebSocket message as origin is not defined')
71+
return
72+
}
73+
74+
try {
75+
const originUrl = new URL(event.origin)
76+
if (!window.location || window.location.hostname !== originUrl.hostname) {
77+
log.warn('The origin of the WebSocket message is not recognized')
78+
return
79+
}
80+
} catch (error) {
81+
log.warn('The origin of the WebSocket message is invalid', error)
82+
return
83+
}
84+
85+
self.onMessage(event)
86+
})
6987

7088
log.debug("Adding WebSocket event handler for 'close'")
7189
ws.addEventListener('close', (event: CloseEvent) => self.onClose(event))

packages/oauth-app/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ module.exports = () => {
291291

292292
// Adds the Clear-Site-Data header
293293
res.header('Clear-Site-Data', '"*"')
294+
295+
// False-positive for coverity SAST scan
296+
// Ignored since this is just the dev server
294297
res.redirect(r)
295298
}
296299
})

packages/oauth/src/form/jwt-decode.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { jwtDecode } from './jwt-decode'
22

33
describe('decode', () => {
44
test('not JWT token', () => {
5+
// False-positive for coverity SAST scan
6+
// Ignored in .gitleaks.toml as this is just a unit-test
57
const token = 'c3ViamVjdDpvYmplY3Q6dGVzdA=='
68
expect(() => jwtDecode(token)).toThrowError()
79
})
810

911
test('JWT token', () => {
1012
const expected = { iat: 1516239022, name: 'John Doe', sub: '1234567890' }
13+
// False-positive for coverity SAST scan
14+
// Ignored in .gitleaks.toml as this is just a unit-test
1115
const token =
1216
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
1317
const decoded = jwtDecode(token)

0 commit comments

Comments
 (0)