Skip to content

Instantly share code, notes, and snippets.

View deangrant's full-sized avatar

Dean Grant deangrant

View GitHub Profile
@deangrant
deangrant / duplicate_values_json.py
Last active February 2, 2024 05:54
Find duplicate values in a nested JSON structure
def find_duplicates(data, seen=None, duplicates=None):
"""
Recursively finds and returns duplicate values in a nested JSON-like structure.
This function traverses through the given data (which can be a dictionary, a list,
or a single value) and identifies values that appear more than once.
Parameters:
data (dict or list): The JSON-like structure (dict or list) to be checked for duplicates.
seen (set, optional): A set to keep track of values already encountered.
@deangrant
deangrant / supported_ciper_suites.js
Created October 26, 2023 07:55
Print all the supported cipher suites by the default SSLServerSocketFactory for JDK.
jrunscript -e "java.util.Arrays.asList(javax.net.ssl.SSLServerSocketFactory.getDefault().getSupportedCipherSuites()).stream().forEach(println)"
@deangrant
deangrant / .bashrc
Created August 30, 2023 18:02
Alias to return matching instances of a vulnerability type using the Snyk CLI
# $ snykchecktype "SQL Injection"
snykchecktype() {
local type="$1"
local output=$(snyk code test .)
echo "$output" | grep -A2 "$type"
}
@deangrant
deangrant / az_functionapp_config_zip.sh
Created July 24, 2023 14:18
Code snippet to create zip package and publish to Azure Function App
npm prune --production
zip -r app.zip . --exclude @.funcignore --exclude .funcignore
az functionapp deployment source config-zip -g ${MY_RESOURCE_GROUP} -n ${MY_APP_NAME} --src app.zip
@deangrant
deangrant / az_waf_keycloak_exposed_path_recommendations.json
Created July 23, 2023 08:35
Azure Web Application Firewall rule to set exposed path recommendations for Keycloak and restrict by host requester header and permitted remote IP addresses.
# Change the {{ host }} value in []matchConditions > {} 0 > [] matchValues to a array of host header
# values allowed and {{ remoteAddr }} value and []matchConditions > {} 2 > [] matchValues to an array
# of remote IP addresses allowed.
# For more information on exposed path recommendations in Keycloak, see
# https://www.keycloak.org/server/reverseproxy#_exposed_path_recommendations
{
"action": "Block",
"matchConditions": [
@deangrant
deangrant / waf-azure-functions-allow-function-url-only.json
Created July 22, 2023 18:21
Azure WAF custom rule to only allow function URLs for Azure Functions, a second match criteria uses the host request header, replace {{ request_headers:host }} with value as a string type.
{
"action": "Block",
"matchConditions": [
{
"matchValues": [
"\\/api\\/([^?&\\n]+)\\?code=([A-Za-z0-9+/=]+)"
],
"matchVariables": [
{
"variableName": "RequestUri"
@deangrant
deangrant / .env
Last active July 22, 2023 07:43
Azure Functions configuration for local Docker deployment, requires nginx reverse proxy for CORS support.
# Sets the network port the container listens on at runtime for NGINX reverse proxy.
NGINX_PORT_EXPOSE=
# Sets the network port the container listens on at runtime for Azure Functions.
AZURE_FUNCTIONS_PORT_EXPOSE=
@deangrant
deangrant / bounding_box_extend_direction.py
Created July 3, 2023 16:21
Create a polygon and define the distance in meters to extend in each direction (bounding box)
import pyproj
from shapely.geometry import (
Polygon
)
# Define the center point of the bounding box in latitude and longitude.
center_latitude = 40.7128
center_longitude = -74.0060
# Define the distance in meters to extend in each direction
@deangrant
deangrant / encode.sh
Created June 29, 2023 08:24
Generates base64-encoded JSON string for Pomerium IDP_SERVICE_ACCOUNT for Azure Active Directory identity provider
# The below command used the Base64 encoding utility to encode the JSON document
# and return the encoded output required for the IDP_SERVICE_ACCOUNT value.
#
# The JSON document requires the following key/value pairs available from
# the app registration
#
# client_id: The unique identifier of the Application (client) ID.
# client_secret: The client secret value generated in certificates & secrets.
# directory_id: The unique identifier of the Directory (tenant) ID.
@deangrant
deangrant / Dockerfile
Last active June 16, 2023 14:11
Contains code snippets for installing and configuring pg_cron within a container, for full details see https://github.com/citusdata/pg_cron.
# Dockerfile for building a PostgreSQL container image.
FROM postgres:14.7-bullseye
# Copies the init.sql file from the local './postgres'directory to the
# '/docker-entrypoint-initdb.d' directory in the container. This directory
# is where PostgreSQL will look for initialization scripts to run when the
# container is first started.
ADD ./postgres/init.sql /docker-entrypoint-initdb.d/init.sql
# Retrieves new list of packages and installs the pg_cron extension