Skip to content

Ensure table and column names escaped #5850

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

Merged
merged 5 commits into from
Jul 31, 2025
Merged

Conversation

hardillb
Copy link
Contributor

Description

Enforce escaping for table and column names

@hardillb hardillb requested a review from Steve-Mcl July 31, 2025 07:14
@hardillb hardillb marked this pull request as draft July 31, 2025 07:16
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.49%. Comparing base (6a59980) to head (8a69d29).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
forge/ee/lib/tables/drivers/postgres-localfs.js 0.00% 17 Missing ⚠️
forge/ee/lib/tables/drivers/postgres-supavisor.js 0.00% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5850      +/-   ##
==========================================
- Coverage   76.56%   76.49%   -0.08%     
==========================================
  Files         369      369              
  Lines       17951    17969      +18     
  Branches     4179     4189      +10     
==========================================
  Hits        13745    13745              
- Misses       4206     4224      +18     
Flag Coverage Δ
backend 76.49% <0.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hardillb hardillb marked this pull request as ready for review July 31, 2025 07:35
Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

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

This PR is fine as it (minus the lint errors), but I have concerns regarding other parts of the original merged PR I think we must handle to mitigate what we can

NOTE: the below is applicable to both drivers

1

https://github.com/FlowFuse/flowfuse/pull/5850/files#diff-41c5997c75a79615b0da0be7da5a91b8daea9331ccf48714137091ebf76e5562R247

this should be whitelisted at best, escaped at minimum

2

https://github.com/FlowFuse/flowfuse/pull/5850/files#diff-41c5997c75a79615b0da0be7da5a91b8daea9331ccf48714137091ebf76e5562R251-R255
col.default is user input and should be vetted for length and type and if string, escaped. Something like:

if (typeof col.default === 'string') {
    const escapedDefault = pgLib.pg.escapeLiteral(col.default)
    columnDef += ` DEFAULT ${escapedDefault}`
} else if (typeof col.default === 'number' || typeof col.default === 'boolean') {
    columnDef += ` DEFAULT ${col.default}`
} else {
    throw new Error(`Unsupported default value type for column ${col.name}`)
}

3

There are no unit tests for the createTable or dropTable functions.

coerce default values
@Steve-Mcl Steve-Mcl merged commit 16a42c6 into main Jul 31, 2025
20 of 21 checks passed
@Steve-Mcl Steve-Mcl deleted the create-table-escape-fields branch July 31, 2025 09:26
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.

2 participants