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

Security : use sed instead of go-replace #528

Open
lasdou opened this issue Oct 16, 2024 · 1 comment
Open

Security : use sed instead of go-replace #528

lasdou opened this issue Oct 16, 2024 · 1 comment

Comments

@lasdou
Copy link

lasdou commented Oct 16, 2024

the binary go-replace has a lot of security issues See list at the end of the issue.

I suggest to use the sed command instead of go-replace

Real exampel For that particular file :

go-replace \
-s "<DOCUMENT_INDEX>" -r "$WEB_DOCUMENT_INDEX" \
-s "<DOCUMENT_ROOT>" -r "$WEB_DOCUMENT_ROOT" \
-s "<ALIAS_DOMAIN>" -r "$WEB_ALIAS_DOMAIN" \
-s "<SERVERNAME>" -r "$HOSTNAME" \
-s "<PHP_SOCKET>" -r "$WEB_PHP_SOCKET" \
-s "<PHP_TIMEOUT>" -r "$WEB_PHP_TIMEOUT" \
--path=/opt/docker/etc/httpd/ \
--path-pattern='*.conf' \
--ignore-empty

I did this :

# Replace markers recursively using sed
find /opt/docker/etc/httpd/ -type f -name '*.conf' -exec sed -i 's|<DOCUMENT_INDEX>|'"$WEB_DOCUMENT_INDEX"'|g' {} +
find /opt/docker/etc/httpd/ -type f -name '*.conf' -exec sed -i 's|<DOCUMENT_ROOT>|'"$WEB_DOCUMENT_ROOT"'|g' {} +
find /opt/docker/etc/httpd/ -type f -name '*.conf' -exec sed -i 's|<ALIAS_DOMAIN>|'"$WEB_ALIAS_DOMAIN"'|g' {} +
find /opt/docker/etc/httpd/ -type f -name '*.conf' -exec sed -i 's|<SERVERNAME>|'"$HOSTNAME"'|g' {} +
find /opt/docker/etc/httpd/ -type f -name '*.conf' -exec sed -i 's|<PHP_SOCKET>|'"$WEB_PHP_SOCKET"'|g' {} +
find /opt/docker/etc/httpd/ -type f -name '*.conf' -exec sed -i 's|<PHP_TIMEOUT>|'"$WEB_PHP_TIMEOUT"'|g' {} +

usr/local/bin/go-replace (gobinary)

Total: 23 (HIGH: 20, CRITICAL: 3)


┌─────────┬────────────────┬──────────┬────────┬───────────────────┬──────────────────────────────────┬──────────────────────────────────────────────────────────────┐
│ Library │ Vulnerability  │ Severity │ Status │ Installed Version │          Fixed Version           │                            Title                             │
├─────────┼────────────────┼──────────┼────────┼───────────────────┼──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ stdlib  │ CVE-2023-24538 │ CRITICAL │ fixed  │ 1.19.1            │ 1.19.8, 1.20.3                   │ golang: html/template: backticks not treated as string       │
│         │                │          │        │                   │                                  │ delimiters                                                   │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-24538                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-24540 │          │        │                   │ 1.19.9, 1.20.4                   │ golang: html/template: improper handling of JavaScript       │
│         │                │          │        │                   │                                  │ whitespace                                                   │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-24540                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2024-24790 │          │        │                   │ 1.21.11, 1.22.4                  │ golang: net/netip: Unexpected behavior from Is methods for   │
│         │                │          │        │                   │                                  │ IPv4-mapped IPv6 addresses                                   │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2024-24790                   │
│         ├────────────────┼──────────┤        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-2879  │ HIGH     │        │                   │ 1.18.7, 1.19.2                   │ golang: archive/tar: unbounded memory consumption when       │
│         │                │          │        │                   │                                  │ reading headers                                              │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-2879                    │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-2880  │          │        │                   │                                  │ golang: net/http/httputil: ReverseProxy should not forward   │
│         │                │          │        │                   │                                  │ unparseable query parameters                                 │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-2880                    │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41715 │          │        │                   │                                  │ golang: regexp/syntax: limit memory used by parsing regexps  │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41715                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41716 │          │        │                   │ 1.18.8, 1.19.3                   │ Due to unsanitized NUL values, attackers may be able to      │
│         │                │          │        │                   │                                  │ maliciously se...                                            │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41716                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41720 │          │        │                   │ 1.18.9, 1.19.4                   │ golang: os, net/http: avoid escapes from os.DirFS and        │
│         │                │          │        │                   │                                  │ http.Dir on Windows                                          │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41720                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41722 │          │        │                   │ 1.19.6, 1.20.1                   │ golang: path/filepath: path-filepath filepath.Clean path     │
│         │                │          │        │                   │                                  │ traversal                                                    │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41722                   │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41723 │          │        │                   │                                  │ golang.org/x/net/http2: avoid quadratic complexity in HPACK  │
│         │                │          │        │                   │                                  │ decoding                                                     │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41723                   │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41724 │          │        │                   │                                  │ golang: crypto/tls: large handshake records may cause panics │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41724                   │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2022-41725 │          │        │                   │                                  │ golang: net/http, mime/multipart: denial of service from     │
│         │                │          │        │                   │                                  │ excessive resource consumption                               │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2022-41725                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-24534 │          │        │                   │ 1.19.8, 1.20.3                   │ golang: net/http, net/textproto: denial of service from      │
│         │                │          │        │                   │                                  │ excessive memory allocation                                  │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-24534                   │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-24536 │          │        │                   │                                  │ golang: net/http, net/textproto, mime/multipart: denial of   │
│         │                │          │        │                   │                                  │ service from excessive resource consumption                  │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-24536                   │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-24537 │          │        │                   │                                  │ golang: go/parser: Infinite loop in parsing                  │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-24537                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-24539 │          │        │                   │ 1.19.9, 1.20.4                   │ golang: html/template: improper sanitization of CSS values   │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-24539                   │
│         ├────────────────┤          │        │                   │                                  ├──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-29400 │          │        │                   │                                  │ golang: html/template: improper handling of empty HTML       │
│         │                │          │        │                   │                                  │ attributes                                                   │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-29400                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-29403 │          │        │                   │ 1.19.10, 1.20.5                  │ golang: runtime: unexpected behavior of setuid/setgid        │
│         │                │          │        │                   │                                  │ binaries                                                     │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-29403                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-39325 │          │        │                   │ 1.20.10, 1.21.3                  │ golang: net/http, x/net/http2: rapid stream resets can cause │
│         │                │          │        │                   │                                  │ excessive work (CVE-2023-44487)                              │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-39325                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-45283 │          │        │                   │ 1.20.11, 1.21.4, 1.20.12, 1.21.5 │ The filepath package does not recognize paths with a \??\    │
│         │                │          │        │                   │                                  │ prefix as...                                                 │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-45283                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-45287 │          │        │                   │ 1.20.0                           │ golang: crypto/tls: Timing Side Channel attack in RSA based  │
│         │                │          │        │                   │                                  │ TLS key exchanges....                                        │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-45287                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2023-45288 │          │        │                   │ 1.21.9, 1.22.2                   │ golang: net/http, x/net/http2: unlimited number of           │
│         │                │          │        │                   │                                  │ CONTINUATION frames causes DoS                               │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2023-45288                   │
│         ├────────────────┤          │        │                   ├──────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│         │ CVE-2024-34156 │          │        │                   │ 1.22.7, 1.23.1                   │ encoding/gob: golang: Calling Decoder.Decode on a message    │
│         │                │          │        │                   │                                  │ which contains deeply nested structures...                   │
│         │                │          │        │                   │                                  │ https://avd.aquasec.com/nvd/cve-2024-34156                   │
└─────────┴────────────────┴──────────┴────────┴───────────────────┴──────────────────────────────────┴──────────────────────────────────────────────────────────────┘

@shawnhooper
Copy link

shawnhooper commented Oct 23, 2024

Amazon Inspector is also flagging go-replace for:

Both of medium severity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants