Skip to content

inject default Angular SSR environment variables for local builds#10706

Open
falahat wants to merge 13 commits into
mainfrom
local_builds_angular_ssr
Open

inject default Angular SSR environment variables for local builds#10706
falahat wants to merge 13 commits into
mainfrom
local_builds_angular_ssr

Conversation

@falahat

@falahat falahat commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

This adds NG_ALLOWED_HOSTS and NG_ALLOWED_PROXY_HEADERS similar to Firebase App Hosting Source Deploys. This is required for Angular SSR to work with Firebase Deployments.

Scenarios Tested

I tested Angular v19 through v22 with local vs source deploys and confirmed that the results were correct and the same (not falling back to CSR for local builds.)

Sample Commands

@wiz-9635d3485b

wiz-9635d3485b Bot commented Jun 24, 2026

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 4 Medium
Software Management Finding Software Management Findings -
Total 4 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replicates the Go buildpack preparer's Angular environment variable injection and validation for NG_TRUST_PROXY_HEADERS and NG_ALLOWED_HOSTS. The feedback recommends adding a defensive check to ensure the parsed package.json is a non-null object before accessing its properties, and extending the NG_TRUST_PROXY_HEADERS validation to check both runtimeEnv and buildEnv to prevent users from bypassing validation.

Comment thread src/deploy/apphosting/prepare.ts Outdated
Comment thread src/deploy/apphosting/prepare.ts Outdated
Comment thread src/deploy/apphosting/prepare.spec.ts Outdated
@falahat falahat force-pushed the local_builds_angular_ssr branch from de626c2 to 5caf8fa Compare June 24, 2026 14:35
@sjjj986 sjjj986 self-assigned this Jun 24, 2026
@falahat falahat marked this pull request as ready for review June 24, 2026 18:48
@falahat falahat requested a review from sjjj986 June 25, 2026 17:35
Comment thread src/deploy/apphosting/prepare.ts Outdated
const parsed: unknown = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
if (parsed && typeof parsed === "object") {
const pkg = parsed as PackageJson;
const deps = { ...pkg.dependencies, ...pkg.devDependencies };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is creating new object in memory and shallow copying each key value dependency and might be inefficient. Maybe its better to check existence directly using pkg.dependencies?.["@angular/core"].

Comment thread src/deploy/apphosting/prepare.ts Outdated
}
}
} catch (e: unknown) {
logLabeledWarning(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our internal version, we are erroring out when isAngularApplication returns an error, so I think we should log error here to match that instead of logging a warning.

Comment thread src/deploy/apphosting/prepare.ts Outdated
} catch (e: unknown) {
logLabeledWarning(
"apphosting",
`Failed to parse package.json in ${appDir}: ${e instanceof Error ? e.message : String(e)}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it'd be better to keep our error message as consistent as possible between go and typescript code "error when checking if application is angular: ... "

Comment thread src/deploy/apphosting/prepare.ts Outdated
"x-forwarded-host,x-forwarded-port,x-forwarded-proto,x-forwarded-for";

// 1. Inject NG_TRUST_PROXY_HEADERS
// If they have defined RUNTIME env vars for the proxy header though we will log a warning that we're overriding it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our preparer go code validates if user-defined proxy headers is a subset of the allowed values, and if so respects user configuration. And it only overrides when user input is empty? Should we match this logic here too in CLI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll match this to defer to the user if they have defined somthing already.

Comment thread src/deploy/apphosting/prepare.ts Outdated
return true;
});

const allowedHostsValue = [...defaultHosts, ...additionalHosts].join(",");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic here is merging user defined hosts with default hosts no matter what situation, while our Go buildpack does not inject default values if the user has defined NG_ALLOWED_HOSTS env var themselves.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll adjust this to trust the user's setting if they have a set value. Same with the user proxy headers.

Comment thread src/deploy/apphosting/prepare.ts Outdated
// 2. Inject/Merge NG_ALLOWED_HOSTS
const projectNumber = await getProjectNumber({ project: projectId });
const sharedDomain = "hosted.app";
const defaultHosts = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the custom domains retrieved dynamically by the control plane during Cloud Build creation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good call out. I think realistically, we won't be able to fetch the custom domains ahead of time in the CLI, so I will document this as a feature gap. For future improvements, we can consolidate the angular handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants