Skip to content

Commit eb28266

Browse files
committed
improv example the help file
1 parent 9c774ac commit eb28266

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

javascript/ql/src/Security/CWE-798/HardcodedCredentials.qhelp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
</p>
2222
</recommendation>
2323

24+
<example>
25+
<p>
26+
The following code example connects to an HTTP request using an hard-codes authentication header
27+
</p>
28+
29+
<sample src="examples/HardcodedCredentialsHttpRequest.js"/>
30+
31+
<p>
32+
Instead, user name and password can be supplied through the environment variables
33+
<code>username</code> and <code>password</code>, which can be set externally without hard-coding
34+
credentials in the source code.
35+
</p>
36+
</example>
37+
2438
<example>
2539
<p>
2640
The following code example connects to a Postgres database using the <code>pg</code> package
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let base64 = require('base-64');
2+
3+
let url = 'http://example.org/auth';
4+
let username = 'user';
5+
let password = 'passwd';
6+
7+
let headers = new Headers();
8+
9+
//headers.append('Content-Type', 'text/json');
10+
headers.append('Authorization', 'Basic' + base64.encode(username + ":" + password));
11+
12+
fetch(url, {method:'GET',
13+
headers: headers,
14+
//credentials: 'user:passwd'
15+
})
16+
.then(response => response.json())
17+
.then(json => console.log(json));
18+
//.done();

0 commit comments

Comments
 (0)