Skip to content

Instantly share code, notes, and snippets.

@FerraBraiZ
FerraBraiZ / CORS simple request safelist.txt
Last active April 9, 2021 17:19
PHP CORS-safelisted request-header
Problemas de CORS
Fonte: https://developer.mozilla.org/pt-BR/docs/Web/HTTP/Controle_Acesso_CORS#Requisi%C3%A7%C3%B5es_simples (TL;DR;)
o Navegador de internet bloqueia requisições que não sejam consideradas simples e seguras, “CORS-safelisted request-header”, ou seja a sua requisição é barrada no proprio navegador e o webserver ( nginx, apache, lighthttpd, etc... ) nem chega a passar (passthrough) a requisição para o PHP ou outro CGI.
ok! mas como eu corrijo ou mitigo esse comportamento???
-> https://gist.github.com/FerraBraiZ/22335146a814b6309fab0a8d6cf9683c
e Afinal o que são requisições simples?
@FerraBraiZ
FerraBraiZ / HTTP_X_FORWARDED_FOR_Properly_Done.php
Created June 29, 2019 14:22
HTTP_X_FORWARDED_FOR properly done
<?php
/*
In the light of the latest httpoxy (https://httpoxy.org/) vulnerabilities,
there is really a need for a full example, how to use HTTP_X_FORWARDED_FOR properly.
So here is an example written in PHP, how to detect a client IP address, if you know
that client may be behind a proxy and you know this proxy can be trusted.
If you don't known any trusted proxies, just use REMOTE_ADDR
*/
@FerraBraiZ
FerraBraiZ / friendly-iframe-stub.js
Created June 29, 2019 12:52
friendly iframe javascript
<script>
/* Originally taken from: https://www.tikalk.com/posts/2017/11/23/your-filename/ */
(function(){
let iframe, domain, doc, where,url;
try {
url = '//locahost:8080/public/friendly-iframe.js';
iframe = document.createElement('iframe');
iframe.src = 'javascript:false';
iframe.title = '';
iframe.role='presentation';
@FerraBraiZ
FerraBraiZ / not-friendly-iframe-stub.js
Last active June 29, 2019 11:57
iframe javascript
<script>
let _iframe = document.createElement("iframe");
_iframe.setAttribute("src", `https://google.com`);
_iframe.style.width = "100%";
_iframe.style.height = "50vh";
_iframe.style.border = "0px";
_iframe.onloadend = function () {
console.info("https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/loadend_event");
};
_iframe.onload = function () {
@FerraBraiZ
FerraBraiZ / GIT-APPT-v2.sh
Created June 22, 2019 17:17
One bash script to fetch from origin and do a hard reset on several branches, this script is useful if u work on several projects at same time and need to sync your local master's with your remote origin, usually github
#!/bin/bash
# EN - GIT AAPT stands for update the whole danm thing
# PT-BR - GIT AAPT significa Atualiza a porra toda
#
REPOSITORIES="$( cd /home/${USER}/public_html/ && pwd )"
IFS=$'\n'
for REPO in `ls "$REPOSITORIES/"`
do
@FerraBraiZ
FerraBraiZ / multi_clone_repos_organization.sh
Last active June 12, 2019 15:57
Shell script to clone every repo ( that u have access that is ;D ) of a github organization
#!/bin/bash
## extracted from https://askubuntu.com/questions/976145/shell-script-to-clone-every-repo-of-a-github-organization
## original author is in the post, all credits goes to him/her/it
for i in $(curl "https://api.github.com/orgs/[organization]/repos?access_token=[access_token]" | sed '/[ ]*"clone_url":/!d;s/[^:]*: "//;s/",$//'); do
echo git clone $i
done
@FerraBraiZ
FerraBraiZ / eventemitter.js
Created November 20, 2018 18:19 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@FerraBraiZ
FerraBraiZ / js
Last active June 29, 2019 04:23
DropZone stub
try{
Dropzone.autoDiscover = false;
const fileTypesWhiteList = "jpeg|jpg|gif|png|bmp|pdf|doc|docx|txt|odt";
let dropZoneFileUploader = new Dropzone("#dz-custom-file-upload-form",{
autoDiscover: false,
autoProcessQueue:false,
uploadMultiple: true,
@FerraBraiZ
FerraBraiZ / php
Last active April 27, 2018 13:06
PHP CURL
<?php
$curl = curl_init();
$url = 'http://localhost:6969/ws/';
$opts = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",