Skip to content

Commit e72a7ad

Browse files
CopilotPhantomDave
andauthored
Fix CodeQL security vulnerabilities in CORS, JWT, logging, and GitHub Actions (#53)
* Initial plan * Fix critical security issues in CORS and JWT configuration Co-authored-by: PhantomDave <34485699+PhantomDave@users.noreply.github.com> * Fix potential token exposure in GitHub Actions workflow Co-authored-by: PhantomDave <34485699+PhantomDave@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PhantomDave <34485699+PhantomDave@users.noreply.github.com>
1 parent a268a51 commit e72a7ad

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

.github/workflows/deploy-tailscale.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ jobs:
120120
121121
- name: Log in to GitHub Container Registry
122122
run: |
123-
tailscale ssh "${{ steps.ssh.outputs.target }}" \
124-
"echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin"
123+
echo "${{ secrets.GITHUB_TOKEN }}" | tailscale ssh "${{ steps.ssh.outputs.target }}" \
124+
"docker login ghcr.io -u ${{ github.actor }} --password-stdin"
125125
126126
- name: Clean up old Docker images
127127
run: |

PhantomDave.BankTracking.Api/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public static void Main(string[] args)
5858
})
5959
.AddJwtBearer(options =>
6060
{
61-
options.RequireHttpsMetadata = false; // enable HTTPS in production
61+
// WARNING: RequireHttpsMetadata should be true in production environments
62+
// Set to false only for local development
63+
options.RequireHttpsMetadata = builder.Environment.IsDevelopment() == false;
6264
options.SaveToken = true;
6365
options.TokenValidationParameters = new TokenValidationParameters
6466
{
@@ -79,7 +81,7 @@ public static void Main(string[] args)
7981
{
8082
options.AddDefaultPolicy(policy =>
8183
policy
82-
.WithOrigins("http://localhost:4200", "http://localhost:5095/graphql", "*")
84+
.WithOrigins("http://localhost:4200", "http://localhost:5095")
8385
.AllowAnyHeader()
8486
.AllowAnyMethod()
8587
.AllowCredentials());

PhantomDave.BankTracking.Api/Services/FileImportService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Text;
33
using CsvHelper;
44
using CsvHelper.Configuration;
5+
using Microsoft.Extensions.Logging;
56
using OfficeOpenXml;
67
using PhantomDave.BankTracking.Api.Types.ObjectTypes;
78
using PhantomDave.BankTracking.Library.Models;
@@ -24,8 +25,10 @@ public class ParsedFileData
2425
public FileType FileTypeExt { get; set; } = FileType.Xlsx;
2526
public int HeaderRowIndex { get; set; } = 1;
2627
}
27-
public class FileImportService
28+
public class FileImportService(ILogger<FileImportService> logger)
2829
{
30+
private readonly ILogger<FileImportService> _logger = logger;
31+
2932
public async Task<ParsedFileData> ParseFileAsync(IFile file)
3033
{
3134
await using var reader = file.OpenReadStream();
@@ -239,8 +242,9 @@ private static Encoding DetectEncoding(Stream stream)
239242
Encoding.UTF8.GetString(buffer, 0, bytesRead);
240243
return Encoding.UTF8;
241244
}
242-
catch
245+
catch (DecoderFallbackException)
243246
{
247+
// If UTF-8 decoding fails, fall back to ISO-8859-1
244248
return Encoding.GetEncoding("ISO-8859-1");
245249
}
246250
}
@@ -283,11 +287,13 @@ public IEnumerable<FinanceRecord> FromParsedData(int accountId, ParsedFileData p
283287

284288
records.Add(record);
285289
}
286-
catch
290+
catch (Exception ex)
287291
{
288292
failedCount++;
293+
_logger.LogWarning(ex, "Failed to parse row {RowIndex} during import", records.Count + failedCount);
289294
}
290-
Console.WriteLine($"Processed {records.Count + failedCount} / {parsedData.Rows.Count}, Failed: {failedCount}");
295+
_logger.LogDebug("Processed {ProcessedRows} / {TotalRows}, Failed: {FailedRows}",
296+
records.Count + failedCount, parsedData.Rows.Count, failedCount);
291297
}
292298

293299
return records;

0 commit comments

Comments
 (0)