Skip to content

Commit f444de2

Browse files
committed
Fix memory leaks and grammar errors, add Dockerfile.test for Valgrind testing
1 parent 7426bd3 commit f444de2

File tree

9 files changed

+877
-50
lines changed

9 files changed

+877
-50
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.sh text eol=lf
2+
.github.workflows.trivy-analysis.yaml text eol=lf

.github/workflows/trivy-analysis.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Checkout code
22-
uses: actions/checkout@v4.2.2
22+
uses: actions/checkout@v5
2323

2424
- name: Run Trivy vulnerability scanner on the cloned repository files
25-
uses: aquasecurity/trivy-action@0.30.0
25+
uses: aquasecurity/trivy-action@0.33.1
2626
with:
27-
version: 'v0.61.1'
27+
version: 'v0.67.0'
2828
scan-type: 'fs'
2929
scanners: 'vuln,misconfig,secret,license'
3030
ignore-unfixed: true
3131
format: 'sarif'
3232
output: ${{ env.SARIF_FILE }}
33-
severity: 'CRITICAL'
33+
severity: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
3434

3535
- name: Check Trivy scan results existence
3636
run: |
@@ -41,7 +41,7 @@ jobs:
4141
ls -lash ${{ env.SARIF_FILE }}
4242
4343
- name: Upload Trivy scan results to GitHub Security tab
44-
uses: github/codeql-action/upload-sarif@v3.28.16
44+
uses: github/codeql-action/upload-sarif@v4
4545
with:
4646
sarif_file: ${{ env.SARIF_FILE }}
4747

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM frolvlad/alpine-gcc:latest
2-
RUN apk add --quiet --no-cache libressl-dev make
2+
# Update packages to get latest security fixes for OpenSSL (CVE-2025-9230, CVE-2025-9231, CVE-2025-9232)
3+
RUN apk update && apk upgrade --no-cache && apk add --quiet --no-cache libressl-dev make
34

45
# Create non-root user and group
56
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
@@ -10,8 +11,8 @@ COPY Makefile /opt/src/
1011
COPY entrypoint.sh /
1112

1213
WORKDIR /opt/src
14+
# Note: Only need one make command on Alpine Linux (macOS paths removed)
1315
RUN make
14-
RUN make OPENSSL=/usr/local/opt/openssl/include OPENSSL_LIB=-L/usr/local/opt/openssl/lib
1516
RUN ["chmod", "+x", "/entrypoint.sh"]
1617
RUN ["chmod", "+x", "/opt/src/jwtcrack"]
1718

Dockerfile.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM frolvlad/alpine-gcc:latest
2+
# Update packages to get latest security fixes for OpenSSL (CVE-2025-9230, CVE-2025-9231, CVE-2025-9232)
3+
RUN apk update && apk upgrade --no-cache && apk add --quiet --no-cache libressl-dev make valgrind bash coreutils
4+
5+
# Create non-root user for security (AVD-DS-0002)
6+
RUN addgroup -S testgroup && adduser -S testuser -G testgroup
7+
8+
COPY ./*.h /opt/src/
9+
COPY ./*.c /opt/src/
10+
COPY Makefile /opt/src/
11+
COPY test_security.sh /opt/src/
12+
13+
WORKDIR /opt/src
14+
15+
# Build with debug symbols for better Valgrind output
16+
RUN make CFLAGS="-g -O0"
17+
RUN chmod +x /opt/src/test_security.sh
18+
RUN chown -R testuser:testgroup /opt/src
19+
20+
USER testuser
21+
22+
CMD ["/opt/src/test_security.sh"]

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ docker build . -t jwtcrack
1616
docker run -it --rm jwtcrack eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.cAOIAifu3fykvhkHpbuhbvtH807-Z2rI1FS3vX1XMjE
1717
```
1818

19+
## Testing with Docker
20+
21+
Build and run the test image which includes Valgrind for memory leak detection:
22+
23+
```
24+
docker build -f Dockerfile.test -t jwtcrack-test .
25+
docker run --rm jwtcrack-test
26+
```
27+
28+
This runs a functional test with 20 threads and a Valgrind memory check.
29+
1930
## Manual Compilation
2031

2132
Make sure you have openssl's headers installed.
@@ -78,6 +89,6 @@ $ > ./jwtcrack eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.eyJyb2xlIjoiYWRtaW4ifQ.31xCH
7889
## IMPORTANT: Known bugs
7990

8091
The base64 implementation I use (from Apple) is sometimes buggy because not every Base64 implementation is the same.
81-
So sometimes, decrypting of your Base64 token will only work partially and thus you will be able to find a secret to your token that is not the correct one.
92+
So sometimes, decrypting your Base64 token will only work partially and thus you will be able to find a secret to your token that is not the correct one.
8293

8394
If someone is willing to implement a more robust Base64 implementation, that would be great :)

base64.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@
8787
#include "base64.h"
8888

8989
/* aaaack but it's fast and const should make it shared text page. */
90+
/* Modified to support both Base64 (+/) and Base64URL (-_) per RFC 4648 */
9091
static const unsigned char pr2six[256] =
9192
{
9293
/* ASCII table */
9394
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
9495
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
95-
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 63,
96+
/* sp ! " # $ % & ' ( ) * + , - . / */
97+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 62, 64, 63,
9698
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
9799
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
98100
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 63,
@@ -149,7 +151,7 @@ int Base64decode(char *bufplain, const char *bufcoded)
149151
nprbytes -= 4;
150152
}
151153

152-
/* Note: (nprbytes == 1) would be an error, so just ingore that case */
154+
/* Note: (nprbytes == 1) would be an error, so just ignore that case */
153155
if (nprbytes > 1) {
154156
*(bufout++) =
155157
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
/opt/src/jwtcrack $@
2+
/opt/src/jwtcrack "$@"

0 commit comments

Comments
 (0)