Skip to content

Commit

Permalink
fix(security): CORS header (remove wildcard) and allow only GET and P…
Browse files Browse the repository at this point in the history
…OST method (#90)

Access-Control-Allow-Origin: * makes everyone able to request to your
api

only allow the current origin, since it's an opensource project, I
didn't wrote the actual domain (choiceof.dev) but the user's http origin
instead
  • Loading branch information
dilaouid authored Nov 19, 2022
1 parent deed5ac commit 1b37d82
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion php/api.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

header("Access-Control-Allow-Origin: *");
if (isset($_SERVER['HTTP_ORIGIN']))
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Methods: GET, POST');

include('../../config.php');

$pdo = new PDO("mysql:dbname=" . $config['DB_NAME'] . ";host=" . $config['DB_HOST'], $config['DB_USER'], $config['DB_PASSWORD']);
Expand Down

0 comments on commit 1b37d82

Please sign in to comment.