この記事の内容
実際に
Gemini Code Assistで 安全な コードを 生成する
Googleが
Gemini Code Assistの
Gemini Code Assistに
AI生成コードを
VS Code(無料!)
Googleの
Gemini Code Assist(無料!) VS Codeの
ユーザー設定に 次の ディレクティブを 追加して、 Gemini Code Assistの 「Insiders」 モードを 有効に してください : "geminicodeassist.updateChannel":"Insiders",
Snyk CLI(無料!)
Snyk VS Code IDE拡張機能(無料!)
Node.jsでユーザープロフィール画像を安全に保存する方法
Expressウェブフレームワークを
index.js内のroutes/ファイルには、save_account_detailsと
Node.jsサーバー上の
exports.save_account_details = function(req, res, next) {
// get the profile details from the JSON
const profile = req.body
// validate the input
if (validator.isEmail(profile.email, { allow_display_name: true })
// allow_display_name allows us to receive input as:
// Display Name <email-address>
// which we consider valid too
&& validator.isMobilePhone(profile.phone, 'he-IL')
&& validator.isAscii(profile.firstname)
&& validator.isAscii(profile.lastname)
&& validator.isAscii(profile.country)
) {
// trim any extra spaces on the right of the name
profile.firstname = validator.rtrim(profile.firstname)
profile.lastname = validator.rtrim(profile.lastname)
// render the view
return res.render('account.hbs', profile)
} else {
// if input validation fails, we just render the view as is
console.log('error in form details')
return res.render('account.hbs')
}
}ご覧のvalidator npmパッケージを
この
GenAIコーディングタスク:ユーザーのアバターでプロフィールを更新する
Node.jsで
VS Codeの
Let's update the save_account_details function handler so that it takes the URL provided in the req.body.profile_picture_url property, downloads the file to the uploads/ directory and saves it to diskGemini Code Assistで

モデルが
exports.save_account_details = function(req, res, next) {
// get the profile details from the JSON
const profile = req.body
// validate the input
if (validator.isEmail(profile.email, { allow_display_name: true })
// allow_display_name allows us to receive input as:
// Display Name <email-address>
// which we consider valid too
&& validator.isMobilePhone(profile.phone, 'he-IL')
&& validator.isAscii(profile.firstname)
&& validator.isAscii(profile.lastname)
&& validator.isAscii(profile.country)
) {
// trim any extra spaces on the right of the name
profile.firstname = validator.rtrim(profile.firstname)
profile.lastname = validator.rtrim(profile.lastname)
if (profile.profile_picture_url) {
const localPath = path.join(__dirname, '../public/uploads/');
if (!fs.existsSync(localPath)) {
fs.mkdirSync(localPath)
}
const localFile = fs.createWriteStream(path.join(localPath, path.basename(profile.profile_picture_url)));
const protocol = profile.profile_picture_url.startsWith('https') ? https : http;
protocol.get(profile.profile_picture_url, function(response) {
response.pipe(localFile);
localFile.on('finish', function() {
localFile.close();
// render the view
return res.render('account.hbs', profile)
});
}).on('error', function(err) {
fs.unlink(localPath);
console.log('error in form details')
return res.render('account.hbs')
});
} else {
// render the view
return res.render('account.hbs', profile)
}
} else {
// if input validation fails, we just render the view as is
console.log('error in form details')
return res.render('account.hbs')
}
}上記の

Snyk AI Trustの名にふさわしく、Gemini Code Assistを保護
日々の
セキュリティリスクの
Gemini Code Assistに

たった
ユーザーが
指定した URLから データを 取得していますが、 HTTPSではなく HTTPの リモートエンドポイントに 接続してしまう 可能性が あります。 その ため Snykは、 機密情報が 平文で 送信される おそれの ある、 安全でない プロトコルの 使用を 警告しています。 この セキュリティリスクに ついては、 Snyk LearnのCookie内の 機密情報の 平文保存で 詳しく 解説しています。 Cookieを 例に 説明しています。 さらに、
ユーザーが 制御する URLに 対して、 検証も せずに HTTPリクエストを 送信しています。 指定された 画像URLが、 社内ネットワークや 開発者の ローカルマシン上に ある http://127.0.0.1:8080/admin_get_resourcesのような 内部リソースだったら どうでしょうか? これは SSRFの 脆弱性です。 この トピックに ついても、 リスクと 緩和策を 詳しく 学べるSnyk Learnの クイックレッスンが あります。サーバーサイドリクエストフォージェリ (SSRF)
では、
MCP経由でGemini Code AssistとSnykを連携し、安全なエージェント型ワークフローを実現
Gemini Code Assistは
Snykも
Gemini Code Assistの.gemini/settings.jsonファイルを
{
"mcpServers": {
"snyk": {
"command": "snyk",
"args": [
"mcp",
"-t",
"stdio",
"--experimental"
]
}
}
}まだ
npm install -g snyk@latest次に、
snyk authすべてが

これで
プロンプトは

Gemini Code Assistが

コーディングセッションは

GenAIコードを保護するSnyk AI Trust
GenAIコードの
バイブコーディングを
していますか? 安全でない コーディングには 注意が 必要です。 実例を ぜひ ご覧ください。Node.jsで バイブコーディングした ファイルアップロードAPIに セキュリティ脆弱性が 発生 MCPを
初めて 使いますか?MCPアーキテクチャを 視覚的に 理解する ための 入門ガイド MCPセキュリティに
ついて 知りたい方は、 こちらを ご覧ください。MCPセキュリティ:古くて 新しい 課題