Skip to content

Commit 25715f4

Browse files
committed
feat: Implement onlyPOST configuration to restrict API to POST requests and enhance security measures
fix: Update base URLs in documentation and examples to reflect new server configuration chore: Add favicon and logo SVG assets for improved branding test: Add integration tests for onlyPOST functionality to ensure correct behavior
1 parent 9915dcc commit 25715f4

25 files changed

Lines changed: 551 additions & 27 deletions

.github/workflows/connector.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ jobs:
6565
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/jodit-nodejs:latest
6666
cache-to: type=inline
6767

68+
- name: Image digest
69+
run: echo ${{ steps.docker.outputs.digest }}
70+
71+
- name: Executing remote ssh commands server1.xdsoft.net
72+
uses: appleboy/ssh-action@master
73+
with:
74+
host: ${{ secrets.HOST_SERVER }}
75+
username: ${{ secrets.USERNAME_SERVER }}
76+
key: ${{ secrets.SSH_PRIVATE_KEY }}
77+
port: ${{ secrets.PORT }}
78+
script: docker system prune -f -a &&
79+
cd /var/www/xdsoft &&
80+
docker compose pull jodit-nodejs &&
81+
docker compose restart jodit-nodejs &&
82+
docker compose up -d jodit-nodejs --force-recreate
83+
6884
publish:
6985
runs-on: ubuntu-latest
7086
needs: test

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ dist/docs/
99
_thumbs
1010
files/test
1111
old-api
12-
docs/.venv/
12+
docs/.venv/
13+
14+
CLAUDE.md
15+
.claude

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ await start({
6868
name: 'uploads',
6969
title: 'User Uploads',
7070
root: '/var/www/uploads',
71-
baseurl: 'http://localhost:8081/uploads/'
71+
// NGINX or CDN base URL for accessing files
72+
baseurl: 'http://localhost:8080/uploads/'
7273
}
7374
}
7475
}
@@ -101,6 +102,34 @@ await start({
101102
});
102103
```
103104

105+
### Security: POST-only Mode
106+
107+
For enhanced security, you can restrict the API to only accept POST requests:
108+
109+
```typescript
110+
import { start } from 'jodit-nodejs';
111+
112+
await start({
113+
port: 8081,
114+
config: {
115+
onlyPOST: true, // Block all GET requests
116+
sources: {
117+
uploads: {
118+
name: 'uploads',
119+
title: 'User Uploads',
120+
root: '/var/www/uploads',
121+
baseurl: 'http://localhost:8080/uploads/'
122+
}
123+
}
124+
}
125+
});
126+
```
127+
128+
When `onlyPOST` is enabled:
129+
- All GET requests return 405 Method Not Allowed
130+
- Provides protection against CSRF attacks
131+
- Prevents parameter leakage in server logs
132+
104133
## Documentation
105134

106135
📖 **[Complete Documentation](https://jodit.github.io/jodit-nodejs/)** - Full documentation with guides and API reference
@@ -127,6 +156,7 @@ await start({
127156
-**Document generation** - PDF and DOCX from HTML
128157
-**Access control** - role-based permissions, path restrictions
129158
-**Authentication** - cookie, JWT, express-session support
159+
-**Security** - POST-only mode, CSRF protection
130160
-**Express integration** - standalone or integrate with existing apps
131161
-**Custom storage** - local filesystem, S3, Azure, Google Cloud, etc.
132162
-**TypeScript** - full type safety with strict typing

docs/assets/images/favicon.svg

Lines changed: 26 additions & 0 deletions
Loading
Lines changed: 19 additions & 0 deletions
Loading

docs/assets/images/jodit-icon.svg

Lines changed: 42 additions & 0 deletions
Loading

docs/assets/images/jodit-logo.svg

Lines changed: 44 additions & 0 deletions
Loading

docs/content/api-usage.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const customConfig: Partial<AppConfig> = {
2424
myfiles: {
2525
title: 'My Files',
2626
root: '/path/to/files',
27-
baseurl: 'http://localhost:8081/files/'
27+
// NGINX or CDN base URL for accessing files
28+
baseurl: 'http://localhost:8080/uploads/'
2829
}
2930
}
3031
};
@@ -74,7 +75,8 @@ async function startWithConfig() {
7475
myfiles: {
7576
title: 'My Files',
7677
root: '/path/to/files',
77-
baseurl: 'http://localhost:8081/files/'
78+
// NGINX or CDN base URL for accessing files
79+
baseurl: 'http://localhost:8080/uploads/'
7880
}
7981
}
8082
};
@@ -149,7 +151,8 @@ const customConfig = {
149151
myfiles: {
150152
title: 'My Files',
151153
root: '/path/to/files',
152-
baseurl: 'http://localhost:8081/files/'
154+
// NGINX or CDN base URL for accessing files
155+
baseurl: 'http://localhost:8080/uploads/'
153156
}
154157
}
155158
};
@@ -209,7 +212,7 @@ node examples/with-express-session.js
209212
## Next Steps
210213

211214
- **[Express Integration](./express-integration.md)** - Integrate with existing Express apps
212-
- **[API Reference](./api-reference.md)** - Complete API endpoints documentation
215+
- **[API Reference](./api.md)** - Complete API endpoints documentation
213216
- **[Authentication](./authentication.md)** - Set up authentication methods
214217
- **[Access Control](./access-control.md)** - Configure permissions and ACL rules
215218
- **[Configuration](./config.md)** - Explore all configuration options

docs/content/config.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ await start({
3838
uploads: {
3939
title: 'Uploads',
4040
root: '/path/to/files',
41-
baseurl: 'http://localhost:8081/files/'
41+
baseurl: 'http://localhost:8080/files/'
4242
}
4343
}
4444
}
@@ -941,6 +941,53 @@ class CustomAccessControl implements IAccessControl {
941941
}
942942
```
943943

944+
### `onlyPOST`
945+
- **Type**: `boolean`
946+
- **Default**: `false`
947+
- **Used**: ✅ Yes
948+
- **Purpose**: Restrict API to only accept POST requests
949+
- **Usage**: When `true`, all GET requests will be blocked with 405 Method Not Allowed
950+
- **Security**: Useful for preventing CSRF attacks and ensuring all API calls use POST method
951+
952+
**Example**:
953+
```typescript
954+
{
955+
onlyPOST: true // Block all GET requests, only allow POST
956+
}
957+
```
958+
959+
**Why use `onlyPOST`?**
960+
961+
By default, Jodit Connector accepts both GET and POST requests. However, in some scenarios you may want to force all requests to use POST method:
962+
963+
1. **CSRF Protection**: GET requests can be triggered from any webpage (via `<img>` tags, `<script>` tags, etc.). By requiring POST, you ensure requests must come from your application's forms.
964+
965+
2. **Security Compliance**: Some security policies require all API mutations to use POST method.
966+
967+
3. **Parameter Privacy**: POST request bodies are not logged in web server access logs, unlike GET query parameters.
968+
969+
When `onlyPOST` is enabled:
970+
- All GET requests return 405 Method Not Allowed error
971+
- POST requests continue to work normally
972+
- This applies to all endpoints including `/ping`
973+
974+
**Client-side configuration** (Jodit editor):
975+
976+
```javascript
977+
Jodit.make('#editor', {
978+
uploader: {
979+
url: 'http://localhost:8081/',
980+
method: 'POST' // Always use POST when onlyPOST is enabled
981+
},
982+
filebrowser: {
983+
ajax: {
984+
url: 'http://localhost:8081/',
985+
method: 'POST' // Always use POST when onlyPOST is enabled
986+
}
987+
}
988+
});
989+
```
990+
944991
### `allowReplaceSourceFile`
945992
- **Type**: `boolean`
946993
- **Default**: `true`
@@ -1021,7 +1068,7 @@ The following parameters are defined in the configuration but are **not currentl
10211068
name: 'default',
10221069
title: 'Files',
10231070
root: '/var/www/files',
1024-
baseurl: 'http://localhost:8081/files/'
1071+
baseurl: 'http://localhost:8080/files/'
10251072
}
10261073
}
10271074
}
@@ -1088,7 +1135,7 @@ The following parameters are defined in the configuration but are **not currentl
10881135
name: 'fast',
10891136
title: 'Fast Storage',
10901137
root: '/ssd/files',
1091-
baseurl: 'http://localhost:8081/files/'
1138+
baseurl: 'http://localhost:8080/files/'
10921139
}
10931140
}
10941141
}

docs/content/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ start({
163163
uploads: {
164164
title: 'Uploads',
165165
root: '/path/to/files',
166-
baseurl: 'http://localhost:8081/files/'
166+
baseurl: 'http://localhost:8080/files/'
167167
}
168168
}
169169
}

0 commit comments

Comments
 (0)