Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
1cb007e8
Commit
1cb007e8
authored
Jan 09, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure we don't store arbitrary data
Explicitly clean DHT records before storing them.
parent
ceab7886
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
handlers.go
handlers.go
+13
-0
No files found.
handlers.go
View file @
1cb007e8
...
...
@@ -152,6 +152,18 @@ func (dht *IpfsDHT) checkLocalDatastore(k string) (*recpb.Record, error) {
return
rec
,
nil
}
// Cleans the record (to avoid storing arbitrary data).
func
cleanRecord
(
rec
*
recpb
.
Record
)
{
rec
.
XXX_unrecognized
=
nil
rec
.
TimeReceived
=
nil
// Only include the author if there's a signature (otherwise, it's
// unvalidated and could be anything).
if
len
(
rec
.
Signature
)
==
0
{
rec
.
Author
=
nil
}
}
// Store a value in this peer local storage
func
(
dht
*
IpfsDHT
)
handlePutValue
(
ctx
context
.
Context
,
p
peer
.
ID
,
pmes
*
pb
.
Message
)
(
_
*
pb
.
Message
,
err
error
)
{
eip
:=
log
.
EventBegin
(
ctx
,
"handlePutValue"
,
p
)
...
...
@@ -169,6 +181,7 @@ func (dht *IpfsDHT) handlePutValue(ctx context.Context, p peer.ID, pmes *pb.Mess
log
.
Infof
(
"Got nil record from: %s"
,
p
.
Pretty
())
return
nil
,
errors
.
New
(
"nil record"
)
}
cleanRecord
(
rec
)
if
err
=
dht
.
verifyRecordLocally
(
rec
);
err
!=
nil
{
log
.
Warningf
(
"Bad dht record in PUT from: %s. %s"
,
peer
.
ID
(
pmes
.
GetRecord
()
.
GetAuthor
()),
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment