-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: enhance security and improve error handling in training and frontend components #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
427a4a5
f20717d
16c3513
c35d10d
492d7b8
9a17336
f7da165
48aad75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,12 @@ resource "aws_s3_bucket_cors_configuration" "datasets" { | |
| cors_rule { | ||
| allowed_headers = ["*"] | ||
| allowed_methods = ["PUT", "GET"] | ||
| allowed_origins = ["*"] | ||
| # Security: Use specific origins instead of wildcard | ||
| # Defaults to Amplify domain + localhost for development | ||
| allowed_origins = length(var.cors_allowed_origins) > 0 ? var.cors_allowed_origins : concat( | ||
| local.amplify_enabled ? ["https://${aws_amplify_app.frontend[0].default_domain}"] : [], | ||
| var.environment == "dev" ? ["http://localhost:3000"] : [] | ||
| ) | ||
| max_age_seconds = 3600 | ||
| } | ||
| } | ||
|
|
@@ -77,7 +82,11 @@ resource "aws_s3_bucket_cors_configuration" "models" { | |
| cors_rule { | ||
| allowed_headers = ["*"] | ||
| allowed_methods = ["GET"] | ||
| allowed_origins = ["*"] | ||
| # Security: Use specific origins instead of wildcard | ||
| allowed_origins = length(var.cors_allowed_origins) > 0 ? var.cors_allowed_origins : concat( | ||
| local.amplify_enabled ? ["https://${aws_amplify_app.frontend[0].default_domain}"] : [], | ||
| var.environment == "dev" ? ["http://localhost:3000"] : [] | ||
| ) | ||
|
||
| expose_headers = ["Content-Disposition"] | ||
| max_age_seconds = 3600 | ||
| } | ||
|
|
@@ -120,7 +129,11 @@ resource "aws_s3_bucket_cors_configuration" "reports" { | |
| cors_rule { | ||
| allowed_headers = ["*"] | ||
| allowed_methods = ["GET"] | ||
| allowed_origins = ["*"] | ||
| # Security: Use specific origins instead of wildcard | ||
| allowed_origins = length(var.cors_allowed_origins) > 0 ? var.cors_allowed_origins : concat( | ||
| local.amplify_enabled ? ["https://${aws_amplify_app.frontend[0].default_domain}"] : [], | ||
| var.environment == "dev" ? ["http://localhost:3000"] : [] | ||
| ) | ||
|
||
| expose_headers = ["Content-Disposition"] | ||
| max_age_seconds = 3600 | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CORS configuration may result in an empty
allowed_originslist in production when Amplify is disabled. Whenvar.cors_allowed_originsis empty,local.amplify_enabledis false (no GitHub integration), andvar.environment != "dev", theconcat()will produce an empty list[], which is invalid for CORS configuration.Recommendation: Add a fallback to prevent empty origins list:
Or require
cors_allowed_originsto be set for production deployments without Amplify.