JWT 서명 검증 누락
Improper Verification of JWT Signature
Last updated
Improper Verification of JWT Signature
Last updated
const jwt = require('jwt-simple');
const secret = process.env.JWT_SECRET;
app.get('/profile', (req, res) => {
const token = req.headers.authorization;
// ⚠️ 검증 없이 디코딩만 함 (서명 미검증)
const decoded = jwt.decode(token, secret, true);
res.json({ user: decoded.username });
});const jwt = require('jwt-simple');
const secret = process.env.JWT_SECRET;
app.get('/profile', (req, res) => {
const token = req.headers.authorization;
try {
// ✅ 서명 검증을 반드시 수행
const decoded = jwt.decode(token, secret, false); // 또는 verify 옵션 생략
res.json({ user: decoded.username });
} catch (error) {
res.status(401).json({ error: 'Unauthorized. Invalid token.' });
}
});