Skip to content

Commit 510116c

Browse files
Fix CodeQL security issues
1 parent 5b0d1eb commit 510116c

File tree

20 files changed

+432
-85
lines changed

20 files changed

+432
-85
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ on:
1515
jobs:
1616
# This workflow contains a single job called "build"
1717
Build-Demo:
18-
if: ${{ github.ref == 'refs/heads/demo' }}
19-
18+
if: ${{ github.ref == 'refs/heads/demo' }}
19+
2020
# The type of runner that the job will run on
2121
runs-on: self-hosted
22+
permissions:
23+
contents: read
2224
env:
2325
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
2426

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
build-and-publish:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
1215
steps:
1316
- name: Checkout repository
1417
uses: actions/checkout@v3

.github/workflows/redirect.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ on:
99
jobs:
1010
# This workflow contains a single job called "redirect"
1111
redirect:
12-
if: ${{ github.ref == 'refs/heads/demo' }}
13-
12+
if: ${{ github.ref == 'refs/heads/demo' }}
13+
1414
# The type of runner that the job will run on
1515
runs-on: self-hosted
16+
permissions:
17+
contents: read
1618
env:
1719
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
1820

README.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ The simplest way to include the SDK is to use either the [**jsDelivr**](https://
3131
- jsDelivr
3232

3333
```html
34-
<script src="https://cdn.jsdelivr.net/npm/[email protected]-beta-202510160004/dist/mrz-scanner.bundle.js"></script>
34+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mrz-scanner.bundle.js"></script>
3535
```
3636

3737
- UNPKG
3838

3939
```html
40-
<script src="https://unpkg.com/[email protected]-beta-202510160004/dist/mrz-scanner.bundle.js"></script>
40+
<script src="https://unpkg.com/[email protected]/dist/mrz-scanner.bundle.js"></script>
4141
```
4242

4343
When using a framework such as **React**, **Vue** or **Angular**, we recommend adding the package as a dependency using a package manager such as **npm** or **yarn**:
4444

45-
```sh
46-
npm i [email protected]-beta-202510160004 -E
47-
# or
48-
yarn add [email protected]-beta-202510160004 -E
49-
```
45+
```sh
46+
47+
# or
48+
yarn add [email protected] -E
49+
```
5050

5151
> [!WARNING]
52-
> When using a package manager like **npm** or **yarn**, you likely need to specify the location of the engine files as a link to a CDN. Please see the [MRZScannerConfig API](https://www.dynamsoft.com/mrz-scanner/docs/web/api/mrz-scanner.html#mrzscannerconfig) for a code snippet on how to set the *engineResourcePaths*.
52+
> When using a package manager like **npm** or **yarn**, you likely need to specify the location of the engine files as a link to a CDN. Please see the [MRZScannerConfig API](https://www.dynamsoft.com/mrz-scanner/docs/web/api/mrz-scanner.html#mrzscannerconfig) for a code snippet on how to set the _engineResourcePaths_.
5353
5454
Below is the complete Hello World sample page that uses the precompiled script served via a CDN.
5555

@@ -60,7 +60,7 @@ Below is the complete Hello World sample page that uses the precompiled script s
6060
<meta charset="utf-8" />
6161
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6262
<title>Dynamsoft MRZ Scanner - Hello World</title>
63-
<script src="https://cdn.jsdelivr.net/npm/[email protected]-beta-202510160004/dist/mrz-scanner.bundle.js"></script>
63+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mrz-scanner.bundle.js"></script>
6464
</head>
6565

6666
<body>
@@ -82,7 +82,7 @@ Below is the complete Hello World sample page that uses the precompiled script s
8282

8383
> [!NOTE]
8484
>
85-
> This code is identical to the Hello World file mentioned in *Build from Source*, except for the script source.
85+
> This code is identical to the Hello World file mentioned in _Build from Source_, except for the script source.
8686
>
8787
> Please do not forget to replace `YOUR_LICENSE_KEY_HERE` with your own license key, whether it is trial or full.
8888
@@ -98,33 +98,35 @@ In this guide, we will show the developer how to build the scanner themselves fr
9898

9999
Please note that we also offer a pre-compiled script reference to make the inclusion of the library even easier. To learn how to use that, please visit the full User Guide for the MRZ Scanner.
100100

101-
This method requires retrieving the **MRZ Scanner for Web** source files from its [Github repository](https://github.com/Dynamsoft/mrz-scanner-javascript), compiles them into a distributable package, and then runs a *ready-made* Hello World sample page that is already included in the repo.
101+
This method requires retrieving the **MRZ Scanner for Web** source files from its [Github repository](https://github.com/Dynamsoft/mrz-scanner-javascript), compiles them into a distributable package, and then runs a _ready-made_ Hello World sample page that is already included in the repo.
102102

103103
Please follow these steps in order to build from the source:
104104

105105
1. Download the **MRZ Scanner for Web** source files from [Github](https://github.com/Dynamsoft/mrz-scanner-javascript) as a compressed folder ("Download ZIP" option).
106106

107107
2. Extract the contents of the compressed folder.
108108

109-
3. Open the *Hello World* sample included with the source files located at `samples/hello-world.html`
109+
3. Open the _Hello World_ sample included with the source files located at `samples/hello-world.html`
110110

111111
4. Search for 'YOUR_LICENSE_KEY_HERE' and replace that with your own license key, whether it is trial or full.
112112

113113
5. Install project dependencies - in the terminal, navigate to the project root directory and run the following:
114-
```bash
115-
npm install
116-
```
114+
115+
```bash
116+
npm install
117+
```
117118

118119
6. Build the project - once the dependencies are installed, build the project by running:
119-
```bash
120-
npm run build
121-
```
120+
121+
```bash
122+
npm run build
123+
```
122124

123125
7. Serve the project via localhost:
124-
```bash
126+
`bash
125127
npm run serve
126-
```
127-
Once the server is running, open the application in a browser using the address provided in the terminal output after running `npm run serve`.
128+
`
129+
Once the server is running, open the application in a browser using the address provided in the terminal output after running `npm run serve`.
128130

129131
## Breaking down Hello World
130132

@@ -139,19 +141,18 @@ Let's now go through the code of the Hello World sample and understand the purpo
139141
<meta charset="utf-8" />
140142
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
141143
<title>Dynamsoft MRZ Scanner - Hello World</title>
142-
<script src="https://cdn.jsdelivr.net/npm/[email protected]-beta-202510160004/dist/mrz-scanner.bundle.js"></script>
144+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mrz-scanner.bundle.js"></script>
143145
</head>
144146

145147
<body>
146148
<h1 style="font-size: large">Dynamsoft MRZ Scanner</h1>
147149
</body>
148-
149150
</html>
150151
```
151152

152153
The first step in setting up the HTML in a Hello World implementation is to include the SDK. The ways to include the SDK has already been addressed in the [Quick Start](#quick-start---including-the-sdk-and-creating-hello-world) section, so please refer to that if you have not already. In this example, we are including the MRZ Scanner via the precompiled script as that is the easiest way to get started.
153154

154-
Since this is a Hello World implementation, the HTML body will be kept quite simple. Since the MRZ Scanner comes with a **Ready-to-Use UI**, it is not necessary to place any `<div>` placeholder elements or anything like. Once the scanner is launched, the **Ready-to-Use UI** will come up and occupy the page.
155+
Since this is a Hello World implementation, the HTML body will be kept quite simple. Since the MRZ Scanner comes with a **Ready-to-Use UI**, it is not necessary to place any `<div>` placeholder elements or anything like. Once the scanner is launched, the **Ready-to-Use UI** will come up and occupy the page.
155156

156157
<!-- The main DOM element that is required in the `<body>` is a `<div>` element where the MRZ result (or lack thereof) and the original image of the MRZ document will be displayed once the user clicks *Done* in the result view. Feel free to customize the styling of the `<div>` element to your liking. -->
157158

@@ -174,7 +175,7 @@ Above you will see the **simplest** way that you can initialize the MRZ Scanner.
174175
(async () => {
175176
// Launch the scanner and wait for the result
176177
const result = await mrzscanner.launch();
177-
console.log(result);
178+
console.log(result);
178179
})();
179180
```
180181

@@ -194,7 +195,7 @@ Here is a quick breakdown of the UI elements that make up the main view of the M
194195

195196
5. **Load Image Button**: When this button is clicked, the user can select a MRZ document image from the device's local storage to be recognized.
196197

197-
6. **Sound Button**: By toggling this on, the MRZ Scanner will play a *beep* sound to signal that the MRZ has been successfully recognized.
198+
6. **Sound Button**: By toggling this on, the MRZ Scanner will play a _beep_ sound to signal that the MRZ has been successfully recognized.
198199

199200
7. **Flash Button**: This button is responsible for toggling the flash of the camera should it have one. If the device doesn't have the flash feature or if the browser being used doesn't support flash, this flash icon will not show up.
200201

@@ -212,9 +213,8 @@ Here is a quick breakdown of the UI elements that make up the result view
212213

213214
4. **Done Button**: Clicking this button basically closes the scanner and destroys the **MRZScanner** instance. At that point, the application will go back to the landing page, but the developer can dictate the action to take once this button is clicked. These actions can include allowing the user to perform some extra actions with the MRZ result, or navigating to another page, or really anything that the developer would like to do once the scanning operation is done.
214215

215-
> [!NOTE]
216-
> In the Hello World sample, no action is taken once the Done button is clicked. The scanner closes and the user is met with an empty page. In order to open the scanner again, the user must refresh the page. You may choose to implement a more user-friendly behavior in a production environment, such as presenting the user with an option to re-open the MRZ Scanner upon closing it.
217-
216+
> [!NOTE]
217+
> In the Hello World sample, no action is taken once the Done button is clicked. The scanner closes and the user is met with an empty page. In order to open the scanner again, the user must refresh the page. You may choose to implement a more user-friendly behavior in a production environment, such as presenting the user with an option to re-open the MRZ Scanner upon closing it.
218218
219219
## Next Steps
220220

dev-server/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import formidable from "formidable";
22
import express from "express";
3+
import rateLimit from "express-rate-limit";
34
import fs from "fs";
45
import http from "http";
56
import https from "https";
@@ -23,6 +24,15 @@ if (!fs.existsSync(distPath)) {
2324

2425
const app = express();
2526

27+
// Rate limiting
28+
const limiter = rateLimit({
29+
windowMs: 15 * 60 * 1000, // 15 minutes
30+
max: 100, // Limit each IP to 100 requests per windowMs
31+
message: "Too many requests from this IP, please try again later.",
32+
});
33+
34+
app.use(limiter);
35+
2636
app.use(
2737
cors({
2838
origin: (origin, callback) => {

dist/mrz-scanner.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mrz-scanner.bundle.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/mrz-scanner.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mrz-scanner.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/mrz-scanner.no-content-bundle.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)