Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't store ip addresses. #62

Merged
merged 1 commit into from
Feb 1, 2016
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
7 changes: 5 additions & 2 deletions appengine/cloudsql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var format = require('util').format;
var express = require('express');
var mysql = require('mysql');
var crypto = require('crypto');

var app = express();
app.enable('trust proxy');
Expand All @@ -33,11 +34,13 @@ var connection = mysql.createConnection({
});

app.get('/', function(req, res, next) {
var hash = crypto.createHash('sha256');

// Add this visit to the database
var visit = {
timestamp: new Date(),
userIp: req.ip
// Store a hash of the ip address
userIp: hash.update(req.ip).digest('hex').substr(0, 7)
};

connection.query('INSERT INTO `visits` SET ?', visit, function(err) {
Expand All @@ -52,7 +55,7 @@ app.get('/', function(req, res, next) {

var visits = results.map(function(visit) {
return format(
'Time: %s, Addr: %s',
'Time: %s, AddrHash: %s',
visit.timestamp,
visit.userIp);
});
Expand Down
8 changes: 6 additions & 2 deletions appengine/datastore/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
var format = require('util').format;
var express = require('express');
var gcloud = require('gcloud');
var crypto = require('crypto');

var app = express();
app.enable('trust proxy');
Expand All @@ -29,12 +30,15 @@ var dataset = gcloud.datastore.dataset({
});

app.get('/', function(req, res, next) {
var hash = crypto.createHash('sha256');

// Add this visit to the datastore
dataset.save({
key: dataset.key('visit'),
data: {
timestamp: new Date(),
userIp: req.ip
// Store a hash of the ip address
userIp: hash.update(req.ip).digest('hex').substr(0, 7)
}
}, function(err) {
if (err) { return next(err); }
Expand All @@ -49,7 +53,7 @@ app.get('/', function(req, res, next) {

var visits = entities.map(function(entity) {
return format(
'Time: %s, Addr: %s',
'Time: %s, AddrHash: %s',
entity.data.timestamp,
entity.data.userIp);
});
Expand Down
6 changes: 5 additions & 1 deletion appengine/disk/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
var fs = require('fs');
var util = require('util');
var express = require('express');
var crypto = require('crypto');

var app = express();
app.enable('trust proxy');

app.get('/', function(req, res, next) {
var instanceId = process.env.GAE_MODULE_INSTANCE || '1';
var userIp = util.format('%s\n', req.ip);
var hash = crypto.createHash('sha256');
// Only store a hash of the ip address
var ip = hash.update(req.ip).digest('hex').substr(0, 7);
var userIp = util.format('%s\n', ip);

fs.appendFile('/tmp/seen.txt', userIp, function(err) {
if (err) { return next(err); }
Expand Down
6 changes: 4 additions & 2 deletions appengine/express-memcached-session/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var session = require('express-session');
var cookieParser = require('cookie-parser');
var MemcachedStore = require('connect-memcached')(session);
var publicIp = require('public-ip');
var crypto = require('crypto');

var app = express();

Expand All @@ -33,9 +34,10 @@ app.use(session({

app.get('/', function(req, res){
publicIp.v4(function (err, ip) {
var hash = crypto.createHash('sha256');

// This shows the IP for each
res.write('<div>' + ip + '</div>');
// This shows the hashed IP for each
res.write('<div>' + hash.update(ip).digest('hex').substr(0, 7) + '</div>');

if(req.session.views) {
++req.session.views;
Expand Down