Skip to content

bug: validate Teradata logon host/user before BTEQ envsubst - #85

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1788936863-bteq-logon-validation
Open

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1788936863-bteq-logon-validation

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes code-scan finding sfind-8b2ffe3dc2ad4b3aa142487d03432771: .LOGON ${TD_SERVER}/${TD_USERNAME},; in the BTEQ scripts (and the heredoc in run_full_pipeline.sh) is expanded by envsubst from unvalidated environment values, so a newline in TD_USERNAME injected extra BTEQ dot-commands (e.g. .OS) and a rewritten TD_SERVER redirected the LDAP logon to an attacker host.

  • config/pipeline_config.cfg: new TD_ALLOWED_SERVERS allow-list and validate_td_logon() (host must match ^[A-Za-z0-9][A-Za-z0-9.-]*$ and be allow-listed; user must match ^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$; LOOKBACK_MONTHS must be an integer 1–120). Runs when the config is sourced, so every orchestrator fails fast on a bad value.
  • BTEQ_SUBST_VARS='${TD_SERVER} ${TD_USERNAME} ${LOOKBACK_MONTHS}'envsubst is now given an explicit SHELL-FORMAT in run_bteq_pipeline.sh and run_full_pipeline.sh, so no other environment variable can be substituted into BTEQ input. validate_td_logon is re-run immediately before each envsubst | bteq.
  • LOOKBACK_MONTHS is the only non-logon placeholder in the BTEQ scripts (02_stg_txn_summary.bteq), so it is included in the allow-list and validated; it now honours an environment override (${LOOKBACK_MONTHS:-12}) like TD_USERNAME, and the config-load validation runs after it is set.

Verified with a stub bteq: default values produce the unchanged .LOGON tdprod.corp.bankdemo.com/svc_etl_pipeline,; and ADD_MONTHS(CURRENT_DATE, -12); TD_USERNAME=$'svc\n.OS touch /tmp/PWNED;', TD_SERVER=evil.attacker.net, LOOKBACK_MONTHS=$'12\n.OS id', 0 and 121 all abort with rc=1 before BTEQ is invoked; an unrelated ${DB_CORE} placeholder is left unsubstituted.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/c58669f7ffc44e7f8ff92a5c16a9c917
Open in Devin Desktop: https://app.devin.ai/desktop/session/c58669f7ffc44e7f8ff92a5c16a9c917?variant=devin
Requested by: @achalc

Pin TD_SERVER to an allow-list and reject TD_USERNAME values containing
whitespace or metacharacters so environment-controlled values cannot
redirect the LDAP logon or inject BTEQ commands. Restrict envsubst to
the logon variables only.

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 1 potential issue.

Devin Review

Comment thread config/pipeline_config.cfg Outdated
Co-Authored-By: Achal Channarasappa <achal.channarasappa@cognition.ai>
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.

1 participant