Skip to content

Instantly share code, notes, and snippets.

View hongphuc5497's full-sized avatar
🐧
Focusing

Hong Phuc hongphuc5497

🐧
Focusing
View GitHub Profile
@zelic91
zelic91 / secure.conf
Last active June 29, 2021 09:39
Secure Nginx Config
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';
add_header Content-Security-Policy "default-src 'self'; font-src *;img-src * data:; script-src *; style-src *";
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options nosniff;
add_header Referrer-Policy "strict-origin";
add_header Permissions-Policy "geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()";
add_header Access-Control-Allow-Origin 'https://<some full domain>';
add_header Access-Control-Allow-Methods 'GET, OPTIONS, HEAD, POST, PUT, DELETE';
add_header Access-Control-Allow-Headers 'Authorization, X-App-Token, X-Access-Token, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type';
@vlucas
vlucas / encryption.js
Last active July 23, 2024 01:24
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);