Skip to content

Commit 703a104

Browse files
author
Bruno Bernardino
committed
Increased security.
- Increased minimum number of options from 2 to 4. - Added random non-visual noise in the images and audio files. Related to desirepath41/visualCaptcha#2 and desirepath41/visualCaptcha#17
1 parent ea9566b commit 703a104

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 emotionLoop
3+
Copyright (c) 2015 emotionLoop
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ By default, they're populated using the ./audios.json file.
7979
- `index` is index of the image in the session images array to send;
8080
- `response` is Node's response object;
8181
- `isRetina`, boolean, defaults to `false`.
82+
83+
84+
## License
85+
View the [LICENSE](LICENSE) file.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.0",
2+
"version": "0.1.1",
33
"name": "visualcaptcha",
44
"description": "Node.js module for visualCaptcha. Still requires you to have the front-end companion.",
55
"keywords": [

visualCaptcha.js

+50-9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ visualCaptcha = {
3737
numberOfOptions = 5;
3838
}
3939

40+
// Set the minimum numberOfOptions to four
41+
if ( numberOfOptions < 4 ) {
42+
numberOfOptions = 4;
43+
}
44+
4045
// Shuffle all imageOptions
4146
this.imageOptions = _.shuffle( this.imageOptions );
4247

@@ -166,19 +171,37 @@ visualCaptcha = {
166171
response.set( 'pragma', 'no-cache' );
167172
response.set( 'expires', 0 );
168173

169-
stream = fs.createReadStream( audioFilePath )
170-
.pipe( response );
174+
stream = fs.createReadStream( audioFilePath );
175+
var responseData = [];
171176

172177
if ( stream ) {
178+
stream.on( 'data', function( chunk ) {
179+
responseData.push( chunk );
180+
});
181+
173182
stream.on( 'end', function() {
174183
if ( ! response.headerSent ) {
175-
response.status( 200 ).send( 'Ok' );
184+
var finalData = Buffer.concat( responseData );
185+
response.write( finalData );
186+
187+
// Add some noise randomly, so audio files can't be saved and matched easily by filesize or checksum
188+
var noiseData = crypto.randomBytes(Math.round((Math.random() * 1999)) + 501).toString('hex');
189+
response.write( noiseData );
190+
191+
response.end();
176192
}
177193
});
178194

179195
stream.on( 'close', function() {
180196
if ( ! response.headerSent ) {
181-
response.status( 200 ).send( 'Ok' );
197+
var finalData = Buffer.concat( responseData );
198+
response.write( finalData );
199+
200+
// Add some noise randomly, so audio files can't be saved and matched easily by filesize or checksum
201+
var noiseData = crypto.randomBytes(Math.round((Math.random() * 1999)) + 501).toString('hex');
202+
response.write( noiseData );
203+
204+
response.end();
182205
}
183206
});
184207
} else {
@@ -233,19 +256,37 @@ visualCaptcha = {
233256
response.set( 'pragma', 'no-cache' );
234257
response.set( 'expires', 0 );
235258

236-
stream = fs.createReadStream( imageFilePath )
237-
.pipe( response );
238-
259+
stream = fs.createReadStream( imageFilePath );
260+
var responseData = [];
261+
239262
if ( stream ) {
263+
stream.on( 'data', function( chunk ) {
264+
responseData.push( chunk );
265+
});
266+
240267
stream.on( 'end', function() {
241268
if ( ! response.headerSent ) {
242-
response.status( 200 ).send( 'Ok' );
269+
var finalData = Buffer.concat( responseData );
270+
response.write( finalData );
271+
272+
// Add some noise randomly, so images can't be saved and matched easily by filesize or checksum
273+
var noiseData = crypto.randomBytes(Math.round((Math.random() * 1999)) + 501).toString('hex');
274+
response.write( noiseData );
275+
276+
response.end();
243277
}
244278
});
245279

246280
stream.on( 'close', function() {
247281
if ( ! response.headerSent ) {
248-
response.status( 200 ).send( 'Ok' );
282+
var finalData = Buffer.concat( responseData );
283+
response.write( finalData );
284+
285+
// Add some noise randomly, so images can't be saved and matched easily by filesize or checksum
286+
var noiseData = crypto.randomBytes(Math.round((Math.random() * 1999)) + 501).toString('hex');
287+
response.write( noiseData );
288+
289+
response.end();
249290
}
250291
});
251292
} else {

0 commit comments

Comments
 (0)