製品開発チームは、リリース前にレビューのためにコード スニペットを送信しました。
手順
コード スニペットを分析し、コード スニペットごとに脆弱性を 1 つ選択し、修正を 1 つ選択します。
コードのスニペット 1

コードスニペット 2

脆弱性 1:
SQLインジェクション
クロスサイトリクエスト偽造
サーバー側のリクエストフォージェリ
間接的なオブジェクト参照
クロスサイトスクリプティング
修正 1:
userid フィールドの入力サニタイズを実行します。
queryResponseの出力エンコーディングを実行し、
usex:ia がログイン ユーザーに属していることを確認してください。
URL を検査し、任意のリクエストを禁止します。
偽造防止トークンを実装します。
脆弱性 2
1) サービス拒否
2) コマンドインジェクション
3) SQLインジェクション
4) 認証バイパス
5) GET 経由で渡される認証情報
修正2
A) プリペアドステートメントを実装してバインドする
変数。
B)serve_forever 命令を削除します。
C) 「認証された」値が GET パラメータによって上書きされないようにします。
D) 機密パラメータには HTTP POST を使用する必要があります。
E) userid フィールドの入力サニタイズを実行します。
正解:
See the solution below in explanation.
Explanation
Code Snippet 1
Vulnerability 1: SQL injection
SQL injection is a type of attack that exploits a vulnerability in the code that interacts with a database. An attacker can inject malicious SQL commands into the input fields, such as username or password, and execute them on the database server. This can result in data theft, data corruption, or unauthorized access.
Fix 1: Perform input sanitization of the userid field.
Input sanitization is a technique that prevents SQL injection by validating and filtering the user input values before passing them to the database. The input sanitization should remove any special characters, such as quotes, semicolons, or dashes, that can alter the intended SQL query. Alternatively, the input sanitization can use a whitelist of allowed values and reject any other values.
Code Snippet 2
Vulnerability 2: Cross-site request forgery
Cross-site request forgery (CSRF) is a type of attack that exploits a vulnerability in the code that handles web requests. An attacker can trick a user into sending a malicious web request to a server that performs an action on behalf of the user, such as changing their password, transferring funds, or deleting data. This can result in unauthorized actions, data loss, or account compromise.
Fix 2: Implement anti-forgery tokens.
Anti-forgery tokens are techniques that prevent CSRF by adding a unique and secret value to each web request that is generated by the server and verified by the server before performing the action. The anti-forgery token should be different for each user and each session, and should not be predictable or reusable by an attacker.
This way, only legitimate web requests from the user's browser can be accepted by the server.