Closed (fixed)
Project:
Security Review
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
29 Feb 2016 at 17:20 UTC
Updated:
14 Feb 2023 at 21:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dsnopekI was thinking about this same thing recently, and thought a whitelist of MD5 hashes of the field content would be best because then it's approving not just a particular entity, but that we know that the actual contents are known to be good. If someone updates the field later with changed script/PHP then we have to re-approve it, but I feel like that's the right thing to do because then you know the new content is trusted too.
Comment #3
dsnopekAh, sorry, I see that you mentioned using an MD5 hash in the issue summary -- I some how skipped over that and just saw the entity id and field. Sorry for the extra noise!
Comment #4
gregglesI'll take your comment as a +1 for the proposed idea. Not noise at all :)
Comment #5
gregglesOK, here's a patch that provides minimal user-facing changes/features while allowing someone comfortable with setting Drupal variables to whitelist content with reasonable ease.
Comment #7
gregglesFor got to change the csv/string/array in one more spot.
Comment #8
dsnopekI haven't tested this and only did a very, very quick look at the code so far but one comment right away:
This will hash twice in the case that a field isn't in the list of known risky fields, which will probably be most fields.
Of course, doing sha256 isn't super performance intensive, but it would make sense to me to stash the hash value in a variable to avoid doing it twice for every value in the majority case.
Comment #9
gregglesYep, thanks for that idea. I had included it at one point and undid some changes and forgot to redo that.
Comment #10
dsnopekI just tested this and it worked as expected! A field on the "Settings" page would make configuring this field way easier (both to do and to explain) but I'm not sure we should make it that easy...
Another super minor bit of patch review:
I'm not super fluent in the different hashing algorithms but it appears that sha-2 is a superset that includes sha-256:
https://security.stackexchange.com/questions/87154/what-is-the-relations...
The docs here should probably say sha-256
Using
db_escape_table()to escape a column is very D6 of you. :-) I'm not totally sure we even need to escape here, as the column is coming from the Field API, and not user input, so probably not? But if we do choose to escape it, it should bedb_escape_field()and we should probably also escape$table, which also comes from the Field API and so is equally trustworthy.Anyway, besides those super minor things, this looks great!
Comment #11
gregglesThanks for the review, dsnopek!
I decided to leave the comment about the safety of the field/table and I changed sha2 to SHA-256 (seems like uppercase is better). I have heard SHA2 used when someone means SHA256 and never realized there was a difference. Thanks for the background.
Comment #12
dsnopekLooks great to me!
Comment #14
gregglesPushed to 7.x.
This now needs to be ported to 8.x.
Comment #15
scottybrookie commentedI apologize for the somewhat ignorant question, but I have content I want to whitelist, and security_review has generated the hash I want to put in the whitelist. My question is, where should I put the whitelist? Where is it supposed to live? The README doesn't specify. Thanks in advance.
Comment #16
gregglesIt's a Drupal variable as a string of comma separated hashes.
You could set it with Drush:
Comment #17
scottybrookie commentedYes, #16 did it for me. Thank you.
Comment #18
gngn commentedHere is a first D8 version of the patch.
For now without any help or README stuff.
I added the config setting known_risky_fields to security_review.check.security_review-field (i.e.
security_review.check.security_review-field:known_risky_fields).It contains sha256 hashes of: entity-type, entity-id, field-name and content.
Because I think a yaml config should be as human readable as possible known_risky_fields is an array (not a comma-separated string like in the D7 version).
For now you can set the values via drush:
php -r "print yaml_emit(['hash1', 'hash2', 'hash2']);" | drush cset security_review.check.security_review-field known_risky_fields --input-format=yaml -The trailing " -" is needed (to read from stdin).
I think we should allow setting known_risky_fields via UI ("Check-specific settings").
Comment #19
gngn commentedNew version of #18:
security_review.check.security_review-field:known_risky_fieldstosecurity_review.check.security_review-field:settings.known_risky_fieldsYou can also set known_risky_fields via drush:
php -r "print yaml_emit(['hash1', 'hash2', 'hash2']);" | drush cset security_review.check.security_review-field settings.known_risky_fields --input-format=yaml -Comment #20
gngn commentedTesting / using #19 I wondered if we should allow a comment to each hash in known_risky_fields to remember the reason why a certain content is considered safe.
That would change the setting to an associative array ('hash1' => 'field body in node XY is safe because ...').
What do you think?
Comment #21
gngn commentedFollowing the thought in #20 I created a patch with comments for each hash line.
I thought there was a usable method to extract values from a "one value per line, in the format key|value" format.
Unfortunately extractAllowedValues() and allowedValuesString() in Drupal\options\Plugin\Field\FieldType\ListItemBase are
static- so I had to copy some of the code from there.Added interdiff to #19 and new patch.
What do you think?
Comment #22
sseto commentedHi Greggles or anyone, hope you will see this after 2 years. I tried #16 and it worked, but some of my pages are using URL parameters to just show content for a specific month (for example, ....../agendas-minutes?date=2019-09). My embedded code is in the sidebar, so it appears to multiple URLs creating hashes. So every time I use add my hash, another one pops up. Is there Anyway around this?
Thank you!
Comment #23
smustgrave commentedIf this is still needed it will need to be rerolled
Comment #24
gregglesUpdating title and IS to be more clear.
Comment #25
smustgrave commentedAttempting to test but could use some instructions for how it should work.
Comment #27
smustgrave commentedWhat about this/
Comment #28
smustgrave commentedComment #29
smustgrave commentedUpdated MR to display hushed findings.
Comment #30
ednark commentedI have tested this and is functions as expected and without errors.
Tested on 10.1.x-dev with a standard install
module drupal/security_review:2.0.x-dev@dev
module branch 2678112-make-fields-check
Test procedure:
Create new Basic Page
Set body wysiwyg to Full Html
add add script tag and save published version of node
goto security_review and run testsa
see failure for that node
goto details of the failure and capture the hash value
goto security_review config page and add "$HASH|reason" as a value to "Dangerous tags in content exclude list" field
rerun security_review test
see success for "Dangerous tags in content"
got to details and see the node still listed, but underneath the "Hushed Findings" header
Comment #32
smustgrave commentedThanks!
Comment #33
jenlamptonThank you for this fix!