Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/labs/hardcoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,59 @@ info =
{
absent: String.raw`^ \s* conn = DriverManager \. getConnection \( url \,`,
text: "Your answer should start with `conn = DriverManager.getConnection( url,` just as the initial value did. You might want to use the `Reset` button.",
text_ja: "回答は元からあるように `conn = DriverManager.getConnection( url,` で始まるはずです。「リセット」ボタンを使うとよいかもしれません。",
},
{
absent: String.raw`System \. getenv`,
text: "Use `System.getenv` to retrieve an environment variable value. For example, use `System.getenv(\"USERNAME\")` to retrieve the username.",
text_ja: "環境変数の値を取得するためには `System.getenv` を使います。例えばユーザ名を取得するためには `System.getenv(\"USERNAME\")` を使ってください。",
},
{
present: String.raw`System \. getenv \( \"admin\" \)`,
text: "You need to pass to `System.getenv` the name of an environment variable value, not the result you might get. Do not use constructs like `System.getenv(\"admin\")`. Instead, for example, use `System.getenv(\"USERNAME\")` to retrieve the username.",
text_ja: "`System.getenv` には取得したい値ではなく、環境変数の名前を渡します。`System.getenv(\"admin\")` の代わりに、例えばユーザ名を取得するためには `System.getenv(\"USERNAME\")` としてください。",
},
{
absent: String.raw`System \. getenv \( \"PASSWORD\" \)`,
text: "Use `System.getenv` to retrieve an environment variable value. For example, use `System.getenv(\"USERNAME\")` to retrieve the username.",
text_ja: "環境変数の値を取得するためには `System.getenv` を使います。例えばユーザ名を取得するためには `System.getenv(\"USERNAME\")` を使ってください。",
},
{
present: "admin",
text: "The term 'admin' should not be in your code. You should be retrieving both the username and the password from somewhere else, in this case, from environment variables.",
text_ja: "'admin' という語句はコードに現れるべきではありません。ユーザ名とパスワードのどちらもどこか他の場所から、今回のケースでは環境変数の値から取得する必要があります。",
},
{
present: "(system|Getenv|GetEnv)",
text: "Java is case-sensitive. You need to use `System.getenv` and not some other variation of uppercase or lowercase.",
text_ja: "Java は大文字と小文字を区別します。`System.getenv` 以外の大文字と小文字の組み合わせを使ってはいけません。",
},
{
absent: String.raw`\; \s* $`,
text: "Java statements must end with a semicolon.",
text_ja: "Java のステートメントはセミコロンで終わる必要があります。",
},
{
absent: String.raw`\) \) \; \s* $`,
text: "Double-check your closing parentheses at the end of the statement.",
text_ja: "ステートメント終わりの右側(閉じ)カッコをもう一度確認してください。",
},
{
present: String.raw`new\s+String`,
text: "You do not need to construct a new string to retrieve an environment variable value.",
text_ja: "環境変数の値を取得するために新たに文字列を作成する必要はありません。",
},
{
present: String.raw`^ conn = DriverManager \. getConnection \( url \) \; \s* $`,
text: "In some sense this is correct, as long as the url is not hardcoded. However, it's often better if administrators can easily change the username or password separately, and it makes out point clearer. Please provide the username and password and separate values.",
text_ja: "URL がハードコードされていない限り、ある意味これは正解です。しかしユーザ名とパスワードを容易にかつ個別に変更できることはしばしば管理者にとって望ましく、かつそれにより問題の本質が明確になります。ユーザ名とパスワードは個別の値としてください。",
},
{
present: String.raw`^ \s* conn = DriverManager \. getConnection \( url \,
System \. getenv \( "PASSWORD" \) \,
System \. getenv \( "USERNAME" \) \) \; \s* $`,
text: "The order of parameters is wrong. Provide the url, then the username, then the password. You're providing the url, then the password, then the username, which swaps the second and third parameters.",
text_ja: "引数の順番に誤りがあります。URL、ユーザ名、パスワードの順としてください。URL、パスワード、ユーザ名の順になっており、二番目と三番目の引数が逆になっています。",
},
],
expected: [
Expand Down
81 changes: 81 additions & 0 deletions docs/labs/ja_hardcoded.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://best.openssf.org/assets/css/style.css">
<link rel="stylesheet" href="checker.css">
<script src="checker.js"></script>
<script src="hardcoded.js"></script>
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">

<!-- See create_labs.md for how to create your own lab! -->
</head>
<body>
<!-- For GitHub Pages formatting: -->
<div class="container-lg px-3 my-5 markdown-body">
<h1>ラボ演習 hardcoded</h1>
<p>
これはセキュアなソフトウェア開発に関するラボ演習です。
ラボの詳細については、<a href="ja_introduction.html" target="_blank">概要</a>をご覧ください。

<p>
<h2>タスク</h2>
<p>
<b>サンプルコードからハードコードされた認証情報を取り除いてください。</b>

<p>
<h2>背景</h2>
<p>
この演習では、ハードコードされた認証情報(この場合はパスワード)をコードから取り除きます。

<p>
<h2>タスクの詳細</h2>
<p>

<p>
以下の Java コードを変更して、ハードコードされた認証情報を取り除いてください。
このコードはハードコードされたユーザ名 "admin" と同じくハードコードされたパスワード "admin" でデータベースシステムにログインします。
最低でも、パスワードはソースコードの中にハードコードして <i>公開すべきものではありません</i>。
パスワードなどの秘密とすべき認証情報がハードコードされていると、不必要に広く公開されてしまい、また変更が困難になります。
ユーザ名も変更される可能性があるので、<i>ハードコードしない</i> 方が賢明です。

<p>
ここでは目的を達成するため、ユーザ名とパスワードを環境変数の値から取得するようにコードを修正します。
ユーザ名(第二引数)は環境変数 <tt>USERNAME</tt> に格納されており、パスワード(第三引数)は環境変数 <tt>PASSWORD</tt> に格納されているものとします。
Java では <tt>System.getenv("FOO")</tt> によって環境変数 <tt>FOO</tt> の値が取得できます。

<p>
環境変数はプログラムのあらゆる部分から参照できてしまうため、汎用的に完璧な手段とはいえません。
より良い他の方法が、あなたが使っているプラットフォームには用意されているかもしれません。
ただしこの場の例としては、移植性に優れており、使うのが簡単で、<i>なにより認証情報をハードコードするよりも良い方法である</i> ことから、環境変数を用います。
注:Java は URL にユーザ名とパスワードを埋め込む形式をサポートしていますが、説明を単純にするためここでは使用しません。

<p>
必要に応じて、「ヒント」ボタンと「諦める」ボタンを使用してください。

<p>
<h2>演習 (<span id="grade"></span>)</h2>
<p>
以下の Java コードを修正し、ハードコードされたパスワードとユーザ名を取り除いてください。
<p>
<form id="lab">
<pre><code
><textarea id="attempt0" rows="3" cols="60" spellcheck="false"
>conn = DriverManager.getConnection(url,
"admin", "admin");</textarea></code></pre>
<button type="button" class="hintButton">ヒント</button>
<button type="button" class="resetButton">リセット</button>
<button type="button" class="giveUpButton">諦める</button>
<br><br>
<p>
<i>このラボは<a href="https://www.microsoft.com/">Microsoft</a>のAvishay Balterによって開発されました。</i>
<br><br>
<p id="correctStamp" class="small">
<textarea id="debugData" class="displayNone" rows="20" cols="65" readonly>
</textarea>
</form>
</div><!-- End GitHub pages formatting -->
</body>
</html>