Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 30 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ jobs:
- name: Build
run: npm run build

- name: Verify SDK distribution
run: npm run check:sdk-dist

- name: Load the classic and module distributions in Chrome
run: |
python3 -m http.server 8765 --bind 127.0.0.1 --directory dist >/dev/null 2>&1 &
server=$!
trap 'kill "$server"' EXIT
node scripts/check-sdk-browser.mjs http://127.0.0.1:8765/

- name: Exercise the Java runtime provider
run: |
archive="$RUNNER_TEMP/graaljs.tar.gz"
release=https://github.com/oracle/graaljs/releases/download/graal-25.0.1
curl -fsSL "$release/graaljs-community-jvm-25.0.1-linux-amd64.tar.gz" -o "$archive"
echo "7dfa228b2e9af3ad4fad77635aa105d55a31838ba522200772131db7d4560af5 $archive" | sha256sum -c -
mkdir "$RUNNER_TEMP/graaljs"
tar -xzf "$archive" --strip-components=1 -C "$RUNNER_TEMP/graaljs"
"$RUNNER_TEMP/graaljs/bin/js" -e '
load("dist/api.js");
if (DecodeBox.capabilities().runtime !== "graaljs-java") throw Error("Java provider missing");
DecodeBox.executeOperation("sha-256", "abc").then(print);
' | grep -Fx ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
node_modules/.bin/rolldown src/engine/tests/java-key-handles.check.js \
--format iife --platform neutral --file "$RUNNER_TEMP/key-handles.js"
"$RUNNER_TEMP/graaljs/bin/js" "$RUNNER_TEMP/key-handles.js" | tee "$RUNNER_TEMP/key-handles.log"
grep -Fxq 'Java key handles passed' "$RUNNER_TEMP/key-handles.log"

- name: Report bundle size
run: |
{
Expand All @@ -67,7 +95,7 @@ jobs:
} >> "$GITHUB_STEP_SUMMARY"

- name: Upload build output
if: matrix.node-version == '22'
if: matrix.node-version == '24'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: dist
Expand Down Expand Up @@ -113,7 +141,7 @@ jobs:
- name: Use Node LTS
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: npm

- name: Install clean packages
Expand Down
74 changes: 39 additions & 35 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ name: Deploy to GitHub Pages
# nothing at all — the site was blank for an afternoon while every check passed.
#
# The branch is force-pushed as a single orphan commit each time. The output is
# 2.7 MB and every file in it is content-hashed, so keeping its history would
# add that much to the repository on every deploy, and not one byte of it would
# ever be read again.
# generated from source. Each tree carries its immutable SDK release directories forward.

on:
push:
Expand All @@ -44,6 +42,7 @@ jobs:
# The only privilege in this workflow, and it exists for one command: the
# push to gh-pages at the end.
contents: write
pages: read

steps:
- name: Checkout
Expand All @@ -56,7 +55,7 @@ jobs:
- name: Use Node LTS
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: npm

- name: Install clean packages
Expand All @@ -65,44 +64,47 @@ jobs:
- name: Build
run: npm run build

# The build ships no CNAME, so no repository claims a domain it does not
# control. Relative asset paths support both the configured custom domain
# and a github.io project URL when no custom domain is configured.
#
# On a branch-served site the CNAME file *is* the custom domain setting,
# and this branch is force-pushed. A repository that has a domain
# configured would lose it the moment it deploys: Pages reads the setting
# back from a file that is no longer there and quietly unsets it. That is
# how a staging site once turned into a 404 in the middle of a release,
# with every check in this workflow green.
#
# So whatever domain the repository has configured is carried forward.
# Pages is asked what it currently is, with the branch's own file as a
# second opinion in case that read is not permitted.
- name: Keep this repository's own custom domain
- name: Check new SDK artifacts and retain published versions
env:
GH_TOKEN: ${{ github.token }}
run: |
rm -f dist/CNAME

raw="https://raw.githubusercontent.com/$GITHUB_REPOSITORY/gh-pages/CNAME"

domain=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.cname // empty' 2>/dev/null || true)
if [ -z "$domain" ]; then
domain=$(curl -fsSL --max-time 30 "$raw" 2>/dev/null | tr -d '[:space:]' || true)
npm run check:sdk-dist
settings=$(gh api "repos/$GITHUB_REPOSITORY/pages")
jq -e '.source.branch == "gh-pages" and .source.path == "/"' <<< "$settings" >/dev/null
domain=$(jq -r '.cname // empty' <<< "$settings")
previous_ref=$(git ls-remote --heads origin refs/heads/gh-pages)
if [[ -n "$previous_ref" ]]; then
git fetch --no-tags --depth=1 origin refs/heads/gh-pages
if [[ -z "$domain" ]] && git cat-file -e FETCH_HEAD:CNAME 2>/dev/null; then
domain=$(git show FETCH_HEAD:CNAME)
fi
if git cat-file -e FETCH_HEAD:sdk 2>/dev/null; then
previous=$(mktemp -d)
git archive FETCH_HEAD sdk | tar -x -C "$previous"
for series in "$previous"/sdk/v*; do
[[ -d "$series" ]] || continue
name=$(basename "$series")
[[ "$name" =~ ^v[0-9]+$ ]] || continue
for release in "$series"/*/; do
target="dist/sdk/$name/$(basename "$release")"
if [[ -d "$release" && -d "$target" ]]; then
diff -qr "$release" "$target"
fi
done
mkdir -p "dist/sdk/$name"
cp -an "$series/." "dist/sdk/$name/"
done
fi
fi

if [ -n "$domain" ]; then
echo "$domain" > dist/CNAME
echo "Keeping the custom domain $domain."
else
echo "No custom domain is configured, so the site stays on github.io."
rm -f dist/CNAME
if [[ -n "$domain" ]]; then
printf '%s\n' "$domain" > dist/CNAME
fi

- name: Verify the build is static and complete
run: |
test -f dist/index.html || { echo "::error::dist/index.html is missing"; exit 1; }
test -f dist/decodebox.html || { echo "::error::dist/decodebox.html is missing - the download button would 404"; exit 1; }
test -s dist/index.html || { echo "::error::dist/index.html is missing"; exit 1; }
test -s dist/decodebox.html || { echo "::error::dist/decodebox.html is missing - the download button would 404"; exit 1; }
# The application must never call out to a third party at runtime. This is a
# coarse check, but it catches an accidental CDN reference before it ships.
if grep -rIloE 'https?://(cdn|unpkg|jsdelivr)' dist --include='*.js' --include='*.html' | head -1 | grep -q .; then
Expand Down Expand Up @@ -176,9 +178,11 @@ jobs:
case "$body" in
*"$entry"*)
echo "$url is serving this build."
npm run check:sdk-dist -- dist "$url"
node scripts/check-sdk-browser.mjs "${url%/}/"
exit 0
;;
*src/main.tsx*)
*src/app/main.tsx*)
# This one never resolves itself: it means Pages is pointed at
# the source branch, so there is no reason to keep waiting.
echo "::error::$url is serving this repository's source index.html instead of the build, so the page is blank. Set Settings -> Pages -> Build and deployment -> Source to 'Deploy from a branch', branch 'gh-pages' / (root)."
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ jobs:
if: steps.target.outputs.tag != ''
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22.23.5'
# Rebuild historical pre-SDK tags with their original toolchain.
node-version: ${{ hashFiles('released-source/scripts/build-sdk.mjs') != '' && '24.18.0' || '22.23.5' }}
package-manager-cache: false

- name: Build the standalone edition
Expand Down Expand Up @@ -150,6 +151,26 @@ jobs:
.tag_name == $tag and .name == ("OWASP DecodeBox " + $tag) and
any(.assets[]; .name == $name and .state == "uploaded" and .digest == $digest)'

- name: Attach SDK integrity manifest to the tagged release
if: steps.target.outputs.tag != ''
working-directory: released-source
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.target.outputs.tag }}
run: |
# Historical tags predate the SDK distribution.
if [[ -f scripts/check-sdk-dist.mjs ]]; then
npm run check:sdk-dist
manifest="dist/sdk/v1/${RELEASE_TAG#v}/SHA256SUMS"
asset="DecodeBox-SDK-$RELEASE_TAG-SHA256SUMS"
cp "$manifest" "$RUNNER_TEMP/$asset"
if gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name' | grep -Fx "$asset"; then
gh release download "$RELEASE_TAG" --pattern "$asset" --output - | cmp - "$manifest"
else
gh release upload "$RELEASE_TAG" "$RUNNER_TEMP/$asset"
fi
fi

- name: Create or update the Release Please PR
if: inputs.release_tag == ''
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sbom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Use Node LTS
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: npm

- name: Install clean packages
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
24
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# OWASP DecodeBox

<img src="public/favicon.svg" alt="DecodeBox logo" width="64" height="64">

[![OWASP Project: Incubator](https://img.shields.io/badge/OWASP_Project-Incubator-blue.svg)](https://owasp.org/projects/)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
[![Live Site](https://img.shields.io/badge/demo-decodebox.owasp.org-orange.svg)](https://decodebox.owasp.org/)
Expand All @@ -21,23 +23,36 @@ evidence you can inspect, and the steps that reach a layer can become an editabl

- **Detection.** Follow nested encodings, including encoded fields inside structured data.
The analysis shows where it found each indicator and what triggered each security finding.
- **Recipes.** Choose from 504 operations to convert formats, decompress data, compute hashes,
- **Recipes.** Use the operation catalogue to convert formats, decompress data, compute hashes,
or extract values. Adjust the arguments, reorder steps, and save the recipe for another input.
- **Capture the flag (CTF).** Search decoded layers for flag patterns, review ranked hints for
the next transformation, and copy the findings into a Markdown report.

## Development
## JavaScript SDK

Embed operation discovery, recipes and multilayer analysis in a browser or Java-enabled GraalJS.
The SDK uses the same local processing engine as the workbench. Run `npm ci` and
`npm run build` with Node.js 24. Save this example as `dist/example.html`, open it in a
browser and check the console for `Hello`.

```html
<meta charset="utf-8">
<script src="./api.js"></script>
<script>
DecodeBox.ready.then(async () => {
console.log(await DecodeBox.executeOperation("from-base64", "SGVsbG8=")); // Hello
});
</script>
```

For local development, clone the [source repository](https://github.com/OWASP/DecodeBox)
and run these commands from its root with Node.js **22.12.0 or later**.
See the [SDK guide](docs/sdk/README.md) for versioned downloads, module imports and integrity
verification. See [runtime integrations](docs/sdk/integrations.md) for TypeScript and ZAP.

```sh
npm ci
npm run dev
```
## Development

Run `npm test -- --run` to execute the 1,205 tests. Run `npm run build` to produce the static
site and the standalone edition.
Use Node.js 24, run `npm ci`, then `npm run dev`. The [development guide](docs/development.md)
covers regression tests and builds for the site, standalone application and SDK. See the
[documentation index](docs/README.md) for the project layout and API reference.

## Standalone Edition

Expand All @@ -60,20 +75,6 @@ Contributions to operations should include test vectors. Follow the
[OWASP contributing guidelines](https://github.com/OWASP/.github/blob/master/CONTRIBUTING.md)
and [Code of Conduct](https://policy.owasp.org/operational/code-of-conduct).

<details>
<summary>Source layout</summary>

- The [engine interface] exposes decoding and analysis to the React [interface components].
- The engine separates [operations], [format detection], and [recursive analysis].

</details>

[Interface components]: src/components/
[engine interface]: src/engine/index.ts
[operations]: src/engine/operations/
[format detection]: src/engine/detection/
[recursive analysis]: src/engine/analysis/

## Project Leader

[Mohammad Hossein Sadeghian](https://github.com/m4sh-wacker)
Expand Down
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# DecodeBox documentation

Use the [workbench](https://decodebox.owasp.org/) to inspect data interactively, or embed the
same operations and analysis engine in an application.

- [Architecture](architecture.md) describes the workbench, worker, engine and runtime providers.
- [Development](development.md) covers local development, tests, builds and publishing.
- [JavaScript SDK](sdk/README.md) covers installation-free loading, distribution and versioning.
- [API reference](sdk/api-reference.md) documents inputs, options, results and failure handling.
- [Integrations](sdk/integrations.md) covers browsers, TypeScript, GraalJS and ZAP.
24 changes: 24 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Architecture

The React entry point lives in [src/app](../src/app/). Components, hooks, Zustand state,
translations and styles have their own directories under `src/`. UI conveniences such as
favorites, recipe sharing and browser storage belong to the application.

The application calls the [engine façade](../src/engine/index.ts), which loads the processing
code on demand. The [worker](../src/engine/worker/) handles work away from the UI thread.
The standalone HTML embeds its scripts, styles and fonts and runs the engine on the main thread.

The [operation registry](../src/engine/operations/index.ts) owns operation IDs, arguments,
metadata and implementations. [Core](../src/engine/core/) executes recipes and handles bytes.
Detection, recursive analysis, inspection and CTF hints use these same operations.
Engine regression tests live in [src/engine/tests](../src/engine/tests/).

The [SDK](../src/sdk/index.ts) validates requests and exposes detached registry metadata.
The classic entry point installs the global object. The module entry point exports the same API.
Neither calls React, the application store or the worker client.

Platform services implement the [runtime interface](../src/engine/runtime/provider.ts).
The web provider uses native browser primitives. The SDK selects the Java provider when GraalJS
exposes Java interop. It uses JCA, SecureRandom, in-memory ZIP streams and Java time zone rules.
Bundled encoding and URL parsers cover APIs that plain GraalJS lacks. The host controls access
to Java classes. New adapters belong behind this internal interface.
44 changes: 44 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Development

Use Node.js 24 for development and distribution. CI also verifies Node.js 22.12 or later in the
22.x series. Install the locked dependencies at the repository root.

```sh
npm ci
npm run dev
```

Before submitting changes, run the same checks as CI.

```sh
npm run lint
npm run typecheck
npm test -- --run
npm run build
npm run check:sdk-dist
```

The build writes the site to `dist/`, the offline application to `dist/decodebox.html`, and
the SDK to the [distribution paths](sdk/README.md#distribution). Use `npm run preview` for
the site, or open the standalone file from disk. `npm run build:sdk` rebuilds the SDK alone.
The distribution check executes both module formats and verifies alias bytes and release hashes.
CI also loads every JavaScript entry point in Chrome and checks SHA-256 with the Java provider.
To run the browser check against a local preview, use the URL printed by Vite.

```sh
node scripts/check-sdk-browser.mjs http://localhost:4173/
```

## Changes and releases

Add operations to the existing registry and supply operation-specific regression vectors.
Keep platform-dependent services in the runtime providers. Changes to public SDK functions
also need contract tests in [src/sdk/sdk.test.ts](../src/sdk/sdk.test.ts) and an API reference
update. Submit changes on a temporary branch targeting `main`.

Release Please manages the project version. The SDK's API major is independent of that version.
The Pages workflow builds from source, carries forward previous SDK releases and the configured
custom domain, and publishes generated files to the root of `gh-pages`. It stops if an existing
version directory would change. A changed release artifact needs a new engine version through
the normal release process. For tags that contain the SDK, the release workflow attaches
the matching checksum manifest. Production bundles and test output stay outside the source tree.
Loading
Loading