Skip to content

Commit d704983

Browse files
authored
Security fixes (#8)
1 parent 7b23cdf commit d704983

File tree

9 files changed

+10880
-94
lines changed

9 files changed

+10880
-94
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ jobs:
99
publish:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: cloudposse/github-action-major-release-tagger@v1
12+
- uses: cloudposse/github-action-major-release-tagger@2

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
contents: write
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121

2222
- name: Run this composite action
2323
id: screenshot
@@ -36,7 +36,7 @@ jobs:
3636
viewportWidth: 2000
3737
viewportHeight: 800
3838

39-
- uses: stefanzweifel/git-auto-commit-action@v4
39+
- uses: stefanzweifel/git-auto-commit-action@v5
4040
name: Commit artifact
4141
id: auto-commit
4242
env:

README.md

Lines changed: 67 additions & 64 deletions
Large diffs are not rendered by default.

action.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ inputs:
1717
output:
1818
description: 'Output image file path'
1919
required: false
20-
default: screenshot.png
20+
default: 'screenshot.png'
2121
outputType:
2222
description: 'Output image type'
23-
default: png
23+
default: 'png'
2424
omitBackground:
2525
description: 'Omit the browser default background. Enable to support transparency.'
26-
default: true
26+
default: 'true'
2727
viewportWidth:
2828
description: 'Viewport width in pixels'
2929
required: true
@@ -34,21 +34,21 @@ inputs:
3434
description: 'Quality of the output image (1-100, applicable for JPEG)'
3535
required: false
3636
consoleOutputEnabled:
37-
descripion: 'Whether or not to output the browser console log'
38-
default: true
37+
description: 'Whether or not to output the browser console log'
38+
default: 'true'
3939
deviceScaleFactor:
4040
description: 'Specifies the device scale factor (pixel ratio) for the web page rendering. It determines how many physical pixels are used to represent a single logical pixel. For example, a device scale factor of 2 means one logical pixel is represented by two physical pixels, commonly used for high-DPI (Retina) displays. A value of 1 uses standard pixel density. This factor affects the resolution and quality of the rendered page or screenshot.'
4141
default: '2'
4242
required: false
4343
fullPage:
4444
description: 'Screen capture the entire page by scrolling down'
45-
default: false
45+
default: 'false'
4646
waitForTimeout:
47-
description: 'Number of miliseconds to delay before taking screenshot'
48-
default: 500
47+
description: 'Number of milliseconds to delay before taking screenshot'
48+
default: '500'
4949
puppeteerImage:
5050
description: 'Docker image to run puppeteer. See https://github.com/puppeteer/puppeteer/pkgs/container/puppeteer'
51-
default: 'ghcr.io/puppeteer/puppeteer:21.7.0'
51+
default: 'ghcr.io/puppeteer/puppeteer:22.13.1'
5252
outputs:
5353
file:
5454
description: "File containing the generated screenshot"
@@ -61,25 +61,25 @@ runs:
6161
shell: bash
6262
run: |
6363
# Ensure node_modules folder will have correct permissions
64-
mkdir -p ${{github.action_path}}/node_modules
64+
mkdir -p '${{ github.action_path }}/node_modules'
6565
6666
# Ensure parent directory containing output file exists
67-
mkdir -p $(dirname "${{ github.workspace }}/${{ inputs.output }}")
67+
mkdir -p $(dirname '${{ github.workspace }}/${{ inputs.output }}')
6868
6969
# Ensure docker container can write this workspace as an unprivileged user
70-
chmod ugoa+rw -R ${{ github.workspace }} ${{github.action_path}}
70+
chmod ugoa+rw -R '${{ github.workspace }}' '${{ github.action_path }}'
7171
7272
# Write out customizations
73-
cat <<__EOF__ | tee -i ${{github.action_path}}/custom.css
73+
cat <<'__EOF__' | tee -i '${{ github.action_path }}/custom.css'
7474
${{ inputs.css }}
7575
__EOF__
7676
77-
cat <<__EOF__ | tee -i ${{github.action_path}}/custom.yaml
77+
cat <<'__EOF__' | tee -i ${{ github.action_path }}/custom.yaml
7878
${{ inputs.customizations }}
7979
__EOF__
8080
8181
# Prepare inputs that should be passed to the docker container.
82-
cat<<__EOF__>docker.env
82+
cat <<'__EOF__' >docker.env
8383
LANG=C.UTF-8
8484
GITHUB_WORKSPACE=${{ github.workspace }}
8585
ACTION_PATH=${{ github.action_path }}
@@ -99,24 +99,25 @@ runs:
9999
cat docker.env
100100
101101
# Avoid duplicate mount points
102-
if [ "$(realpath ${{ github.workspace }})" == "$(realpath ${{ github.action_path }})" ]; then
103-
echo "DOCKER_VOLUMES=-v ${{ github.workspace }}:${{ github.workspace }}:rw" >> "$GITHUB_ENV"
102+
if [ "$(realpath "${{ github.workspace }}")" == "$(realpath "${{ github.action_path }}")" ]; then
103+
echo "DOCKER_VOLUMES=-v "${{ github.workspace }}":"${{ github.workspace }}":rw" >> "$GITHUB_ENV"
104104
else
105-
echo "DOCKER_VOLUMES=-v ${{ github.workspace }}:${{ github.workspace }}:rw -v ${{ github.action_path }}:${{ github.action_path }}:rw" >> "$GITHUB_ENV"
105+
echo "DOCKER_VOLUMES=-v "${{ github.workspace }}":"${{ github.workspace }}":rw -v "${{ github.action_path }}":"${{ github.action_path }}":rw" >> "$GITHUB_ENV"
106106
fi
107107
108108
- name: Run puppeteer to take screenshot
109109
id: screenshot
110110
uses: tj-actions/docker-run@v2
111111
with:
112-
image: ${{ inputs.puppeteerImage }}
112+
image: "${{ inputs.puppeteerImage }}"
113113
name: puppeteer-chrome
114-
options: '-i --init --cap-add=SYS_ADMIN ${{ env.DOCKER_VOLUMES }} --workdir=${{github.action_path}} --env-file docker.env'
114+
# No quotes around ${{ env.DOCKER_VOLUMES }} because it is a list of arguments
115+
options: '-i --init --cap-add=SYS_ADMIN ${{ env.DOCKER_VOLUMES }} --workdir="${{github.action_path}}" --env-file docker.env'
115116
args: |
116117
bash -c './entrypoint.sh'
117118
118119
- id: context
119120
shell: bash
120121
run: |
121-
echo "file=${{ inputs.output }}" >> $GITHUB_OUTPUT
122+
printf 'file=%s\n' '${{ inputs.output }}' >> $GITHUB_OUTPUT
122123

docs/example.png

-216 KB
Loading

docs/github-action.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
| Name | Description | Default | Required |
66
|------|-------------|---------|----------|
7-
| consoleOutputEnabled | consoleOutputEnabled | true | false |
7+
| consoleOutputEnabled | Whether or not to output the browser console log | true | false |
88
| css | Custom CSS overrides | N/A | false |
99
| customizations | String representation of a YAML or JSON map of CSS paths (key) and replacement (value) | N/A | false |
1010
| deviceScaleFactor | Specifies the device scale factor (pixel ratio) for the web page rendering. It determines how many physical pixels are used to represent a single logical pixel. For example, a device scale factor of 2 means one logical pixel is represented by two physical pixels, commonly used for high-DPI (Retina) displays. A value of 1 uses standard pixel density. This factor affects the resolution and quality of the rendered page or screenshot. | 2 | false |
@@ -13,10 +13,11 @@
1313
| omitBackground | Omit the browser default background. Enable to support transparency. | true | false |
1414
| output | Output image file path | screenshot.png | false |
1515
| outputType | Output image type | png | false |
16+
| puppeteerImage | Docker image to run puppeteer. See https://github.com/puppeteer/puppeteer/pkgs/container/puppeteer | ghcr.io/puppeteer/puppeteer:22.13.1 | false |
1617
| url | URL of the HTML content to convert to an image. Use file:// for local files | N/A | true |
1718
| viewportHeight | Viewport height in pixels | N/A | true |
1819
| viewportWidth | Viewport width in pixels | N/A | true |
19-
| waitForTimeout | Number of miliseconds to delay before taking screenshot | 500 | false |
20+
| waitForTimeout | Number of milliseconds to delay before taking screenshot | 500 | false |
2021

2122

2223
## Outputs

main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const puppeteer = require('puppeteer');
22
const fs = require('fs').promises; // Import the fs module
33
const fsSync = require('fs');
44
const yaml = require('js-yaml');
5+
const { setTimeout } = require('node:timers/promises');
56

67
const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE || '.';
78
const INPUT_OUTPUT = process.env.INPUT_OUTPUT || 'docs/example.png';
@@ -60,7 +61,7 @@ async function readYamlFile(filePath) {
6061
await page.goto(INPUT_URL, {
6162
waitUntil: 'networkidle2',
6263
});
63-
await page.waitForTimeout(INPUT_WAIT_FOR_TIMEOUT);
64+
await setTimeout(INPUT_WAIT_FOR_TIMEOUT);
6465

6566
// Check if the custom.css file exists
6667
if (fsSync.existsSync('custom.css')) {
@@ -70,7 +71,7 @@ async function readYamlFile(filePath) {
7071
}
7172

7273
if (fsSync.existsSync('custom.yaml')) {
73-
console.log('Rewritting content');
74+
console.log('Rewriting content');
7475
// Read the element paths from the file
7576
const elementPaths = await readYamlFile('custom.yaml');
7677

@@ -88,7 +89,7 @@ async function readYamlFile(filePath) {
8889
});
8990
}, elementPaths);
9091

91-
await page.waitForTimeout(2000);
92+
await setTimeout(2000);
9293

9394
}
9495
if (INPUT_OUTPUT_TYPE == "jpeg") {

0 commit comments

Comments
 (0)