Skip to content

Commit

Permalink
fix: check System and GitHub time and throw and error if it is over 5…
Browse files Browse the repository at this point in the history
…0s out of sync
  • Loading branch information
peaklabs-dev committed Jan 6, 2025
1 parent 1a36e7b commit 05113d8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bootstrap/helpers/github.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@

function generateGithubToken(GithubApp $source, string $type)
{
$response = Http::get("{$source->api_url}/zen");
$serverTime = now();
$githubTime = Carbon::parse($response->header('date'));
$timeDiff = abs($serverTime->diffInSeconds($githubTime));

if ($timeDiff > 0) {
throw new \Exception(
"System time is out of sync with GitHub API time:\n".
"- System time: {$serverTime->format('Y-m-d H:i:s')} UTC\n".
"- GitHub time: {$githubTime->format('Y-m-d H:i:s')} UTC\n".
"- Difference: {$timeDiff} seconds\n".
'Please synchronize your system clock.'
);
}

$signingKey = InMemory::plainText($source->privateKey->private_key);
$algorithm = new Sha256;
$tokenBuilder = (new Builder(new JoseEncoder, ChainedFormatter::default()));
Expand Down

0 comments on commit 05113d8

Please sign in to comment.