Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Python library which makes it possible to dynamically mask/anonymize data using JSON string or python dict rules in a PySpark environment.
Python library which makes it possible to dynamically mask/anonymize data using JSON string or python dict rules in a PySpark environment.
pip install pyspark-anonymizer
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("your_app_name").getOrCreate()
df = spark.read.parquet("s3://amazon-reviews-pds/parquet/product_category=Electronics/")
df.limit(5).toPandas()
marketplace | customer_id | review_id | product_id | product_parent | product_title | star_rating | helpful_votes | total_votes | vine | verified_purchase | review_headline | review_body | review_date | year | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | US | 51163966 | R2RX7KLOQQ5VBG | B00000JBAT | 738692522 | Diamond Rio Digital Player | 3 | 0 | 0 | N | N | Why just 30 minutes? | RIO is really great, but Diamond should increa... | 1999-06-22 | 1999 |
1 | US | 30050581 | RPHMRNCGZF2HN | B001BRPLZU | 197287809 | NG 283220 AC Adapter Power Supply for HP Pavil... | 5 | 0 | 0 | N | Y | Five Stars | Great quality for the price!!!! | 2014-11-17 | 2014 |
2 | US | 52246039 | R3PD79H9CTER8U | B00000JBAT | 738692522 | Diamond Rio Digital Player | 5 | 1 | 2 | N | N | The digital audio "killer app" | One of several first-generation portable MP3 p... | 1999-06-30 | 1999 |
3 | US | 16186332 | R3U6UVNH7HGDMS | B009CY43DK | 856142222 | HDE Mini Portable Capsule Travel Mobile Pocket... | 5 | 0 | 0 | N | Y | Five Stars | I like it, got some for the Grandchilren | 2014-11-17 | 2014 |
4 | US | 53068431 | R3SP31LN235GV3 | B00000JBSN | 670078724 | JVC FS-7000 Executive MicroSystem (Discontinue... | 3 | 5 | 5 | N | N | Design flaws ruined the better functions | I returned mine for a couple of reasons: The ... | 1999-07-13 | 1999 |
In this example we will add the following data anonymizers:
from pyspark.sql import SparkSession
import pyspark.sql.functions as spark_functions
import pyspark_anonymizer
spark = SparkSession.builder.appName("your_app_name").getOrCreate()
df = spark.read.parquet("s3://amazon-reviews-pds/parquet/product_category=Electronics/")
dataframe_anonymizers = [
{
"method": "drop_column",
"parameters": {
"column_name": "marketplace"
}
},
{
"method": "replace",
"parameters": {
"column_name": "customer_id",
"replace_to": "*"
}
},
{
"method": "replace_with_regex",
"parameters": {
"column_name": "review_id",
"replace_from_regex": "R\d",
"replace_to": "*"
}
},
{
"method": "sha256",
"parameters": {
"column_name": "product_id"
}
},
{
"method": "filter_row",
"parameters": {
"where": "product_parent != 738692522"
}
}
]
df_parsed = pyspark_anonymizer.Parser(df, dataframe_anonymizers, spark_functions).parse()
df_parsed.limit(5).toPandas()
customer_id | review_id | product_id | product_parent | product_title | star_rating | helpful_votes | total_votes | vine | verified_purchase | review_headline | review_body | review_date | year | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | * | RPHMRNCGZF2HN | 69031b13080f90ae3bbbb505f5f80716cd11c4eadd8d86... | 197287809 | NG 283220 AC Adapter Power Supply for HP Pavil... | 5 | 0 | 0 | N | Y | Five Stars | Great quality for the price!!!! | 2014-11-17 | 2014 |
1 | * | *U6UVNH7HGDMS | c99947c06f65c1398b39d092b50903986854c21fd1aeab... | 856142222 | HDE Mini Portable Capsule Travel Mobile Pocket... | 5 | 0 | 0 | N | Y | Five Stars | I like it, got some for the Grandchilren | 2014-11-17 | 2014 |
2 | * | *SP31LN235GV3 | eb6b489524a2fb1d2de5d2e869d600ee2663e952a4b252... | 670078724 | JVC FS-7000 Executive MicroSystem (Discontinue... | 3 | 5 | 5 | N | N | Design flaws ruined the better functions | I returned mine for a couple of reasons: The ... | 1999-07-13 | 1999 |
3 | * | *IYAZPPTRJF7E | 2a243d31915e78f260db520d9dcb9b16725191f55c54df... | 503838146 | BlueRigger High Speed HDMI Cable with Ethernet... | 3 | 0 | 0 | N | Y | Never got around to returning the 1 out of 2 ... | Never got around to returning the 1 out of 2 t... | 2014-11-17 | 2014 |
4 | * | *RDD9FILG1LSN | c1f5e54677bf48936fb1e9838869630e934d16ac653b15... | 587294791 | Brookstone 2.4GHz Wireless TV Headphones | 5 | 3 | 3 | N | Y | Saved my. marriage, I swear to god. | Saved my.marriage, I swear to god. | 2014-11-17 | 2014 |
You can store anonymizers on DynamoDB too.
To create the table follow the steps below.
Using example script
On AWS console:
You can run the example script, then edit your settings from there.
from pyspark.sql import SparkSession
import pyspark.sql.functions as spark_functions
import pyspark_anonymizer
import boto3
from botocore.exceptions import ClientError as client_error
dynamo_table = "pyspark_anonymizer"
dataframe_name = "table_x"
dynamo_table = boto3.resource('dynamodb').Table(dynamo_table)
spark = SparkSession.builder.appName("your_app_name").getOrCreate()
df = spark.read.parquet("s3://amazon-reviews-pds/parquet/product_category=Electronics/")
df_parsed = pyspark_anonymizer.ParserFromDynamoDB(df, dataframe_name, dynamo_table, spark_functions, client_error).parse()
df_parsed.limit(5).toPandas()
The output will be same as the previous. The difference is that the anonymization settings will be in DynamoDB
FAQs
Python library which makes it possible to dynamically mask/anonymize data using JSON string or python dict rules in a PySpark environment.
We found that pyspark-anonymizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.