Skip to content

Commit b9e1c23

Browse files
authored
Merge pull request #6 from VanceHud/main
修复了几个BUG
2 parents 78e7490 + b8530d8 commit b9e1c23

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

.github/workflows/docker-image.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches: [ "main" ]
88
workflow_dispatch:
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
build:
1215
runs-on: ubuntu-latest

server/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ app.get('/api/status', (req, res) => {
112112
});
113113
});
114114

115-
// Setup Routes (Always available, but logic inside checks if already configured)
116-
app.use('/api/setup', setupRoutes);
117-
118115
// Rate Limiter & User Identification
119116
// Apply soft authentication (identifyUser) and rate limiting (rateLimiter)
120117
// identifyUser must come before rateLimiter so we can check roles
121118
app.use('/api', identifyUser, rateLimiter);
122119

120+
// Setup Routes (Always available, but logic inside checks if already configured)
121+
// Now protected by rate limiting to prevent DoS attacks
122+
app.use('/api/setup', setupRoutes);
123+
123124
// App Routes (Only work if configured)
124125
const requireConfig = (req, res, next) => {
125126
if (!isConfigured()) {

server/routes/admin-notifications.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ router.post('/', authenticateToken, requireAdminRole, async (req, res) => {
6464
return res.status(400).json({ error: '邮箱地址不能为空' });
6565
}
6666

67-
// Email validation
68-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
67+
// Email validation - using a safer regex pattern to prevent ReDoS
68+
const emailRegex = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
6969
if (!emailRegex.test(email)) {
7070
return res.status(400).json({ error: '邮箱地址格式不正确' });
7171
}

server/routes/email-templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ router.put('/:key', authenticateToken, requireSuperAdmin, async (req, res) => {
6262

6363
res.json({ success: true });
6464
} catch (err) {
65-
console.error(`Error updating email template ${key}:`, err);
65+
console.error('Error updating email template:', { key, error: err });
6666
res.status(500).json({ error: 'Failed to update template' });
6767
}
6868
});

server/routes/knowledge-base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const router = express.Router();
1111
const generateSlug = (title) => {
1212
return title
1313
.toLowerCase()
14-
.replace(/[^\w\u4e00-\u9fa5]+/g, '-') // Keep Chinese characters
15-
.replace(/^-+|-+$/g, '')
14+
.replace(/[^\w\u4e00-\u9fa5]+/g, '-') // Keep Chinese characters - replace sequences of non-word/non-Chinese chars with single dash
15+
.replace(/^-|-$/g, '') // Remove leading/trailing dashes
1616
.substring(0, 100);
1717
};
1818

0 commit comments

Comments
 (0)