惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

NodeJS Security & NodeJS Secure Coding's Blog

Hardening Your npm and pnpm Configs in the Age of Shai-Hulud Argument Injection vulnerability in git-blame@1.4.0 Argument Injection vulnerability in `gits@0.1.8` Command Injection vulnerability in `@fab1o/git@1.4.0` Command Injection vulnerability in `git-contributors` via unsanitized CLI arguments Command Injection vulnerability in `git-q@0.0.3` Command injection vulnerability via unsanitized CLI arguments in touxing/fast-git-clone Command Injection vulnerability in `willitmerge@0.2.1` A Directory Traversal Vulnerability I found in Mastra AI Frameworks MCP Server Mastering NPX: A Cheatsheet for npm and Node.js Power Users Mitigate Supply Chain Security with DevContainers and 1Password for Node.js Local Development The Tale of the Vulnerable MCP Database Server Bad Security Defaults in Mastra AI Frameworks Templates SQL Injection and Bypassing "Read-Only" Mode in Xata's MCP Server Security Advisory for qix npm supply-chain compromise affecting debug and billions of weekly download users How to Mitigate SQL Bypass in MCP Servers Enhancing MCP Server Security: A Guide to Using execFile Argument Injection Vulnerability in ggit Command Injection Flaws in ggit: Unveiling a Vulnerability Command Injection Vulnerability in Create MCP Server STDIO Tool Exposes System Monitoring Functions GitHub Kanban MCP Server Command Injection Vulnerability Threatens Developer Workflows Critical Command Injection Flaw in iOS Simulator MCP Server Exposes Development Environments Command Injection Vulnerability Discovered in Codehooks MCP Server: A Critical Security Analysis SSRF Shenanigans in safe-axios: Redirects Open the Backdoor SSRF Vulnerability in safe-axios: Unintended Public Address Classification Bypassing SSRF Safeguards in ssrfcheck: A Case of Incomplete Denylists Don't Be Fooled by Multicast, SSRF Bypass in private-ip Node.js Authentication from Lucia to Better Auth Bypassing SSRF Protection in nossrf: When Your Safeguards Become Loopholes Vue CLI Security Fix to Mitigate NPM Binary Planting Node.js API Security Vulnerabilities with Path Traversal in files-bucket-server Will You Accept These GPT 4o Secure Coding Recommendations? Command Injection Vulnerability in interactive-git-checkout npm package An Introduction to SSRF Bypasses and Denylist Failures Disclosing a Command Injection Vulnerability in `git-checkout-tool` Prisma Raw Query Leads to SQL Injection? Yes and No Flawed Git Promises Library on npm Leads to Command Injection Vulnerability Regex Gone Wrong: How parse-duration npm Package Can Crash Your Node.js App How I found an XSS in the Nuxt MDC Library for Markdown Content Holes in the Safety Net: Bypassing SSRF Protection in safe-axios How to Parse URLs from Markdown to HTML Securely? NPM Ignore Scripts Best Practices as Security Mitigation for Malicious Packages Where to find npm vulnerabilities? How to Hunt for IDOR Vulnerabilities To Exploit Security Misconfiguration? How to Avoid JWT Security Mistakes in Node.js Can a Node.js Secure Code Review Find Future Vulnerabilities? The Okta bcrypt Security Incident and The Bun vs Node.js Angle in Secure By Design NodeJS Path Traversal Vulnerability Scanner Do not use secrets in environment variables and here's how to do it better How to use npm audit How to use yarn audit Raw SQL Queries are Actually Better for Security Than ORMs? Node API Security Is Node.js Secure? URL Regex Validation: what can go wrong? Uncovering a Prototype Pollution Regression in the core Node.js project Deno CLI Vulnerability Repeats npm mistakes: CVE-2024-37150 Security skills for JavaScript developers Understanding and Preventing Prototype Pollution in Node.js How to protect against a security breach in React Server Components IDOR Vulnerability: What is it and how to prevent it? The security vulnerability of serving images via a route as opposed to static middleware in Node.js Why is it considered a bad practice to write raw SQL commands? JS Security Concepts for JavaScript Developers Secure Coding Practices in Node.js Against Path Traversal Vulnerabilities Secure JavaScript Coding Practices Against Command Injection Vulnerabilities To IDOR or Not to IDOR: Insecure Direct Object Reference in JavaScript Applications Explained npm vulnerabilities: reviewing the security of your dependencies Disclosing code injection vulnerabilities in safe-eval-2 npm package Introducing Node.js Security Permissions Model, Threat Model, and Security Releases Common Node.js Security Issues and How to Mitigate Them How JavaScript developers should embrace npm security The XZ backdoor CVE-2024-3094: a JavaScript perspective Node.js Security Best Practices The Case for Node.js Secure Configuration Protecting Against Common Node.js Vulnerabilities Input Validation Security Best Practices for Node.js A Node.js Vulnerability Scanner to Avoid Security Risks of EOL Runtime Versions JavaScript Security Issues in Node.js Applications OWASP Node.js Authentication, Authorization and Cryptography Practices OWASP Node.js Best Practices Guide Secure JavaScript Coding to Avoid Insecure Direct Object References (IDOR) North Korea malware on npm and Ledger connect-kit crypto heist 10 Best Practices for Secure Code Review of Node.js code Node.js and OWASP Top Ten Command Injection: Don't Let Your App Go 'BOOM' Secure Code Review Tips to Defend Against Vulnerable Node.js Code Destroyed by Dashes: How Two Hyphens Cause Argument Injection Vulnerability in blamer npm Package Securing Your Node.js Apps by Analyzing Real-World Command Injection Examples An Introduction to Command Injection Vulnerabilities in Node.js and JavaScript
How to Bypass Access Control in PostgreSQL in Simple PSQL MCP Server for SQL Injection
2025-08-18 · via NodeJS Security & NodeJS Secure Coding's Blog

The Model Context Protocol (MCP) ecosystem has rapidly expanded beyond simple file operations and command-line tools to include sophisticated database integrations for agentic workflows an AI IDE like Cursor, Windsurf and others. As AI agents become more capable of managing complex data workflows, MCP Servers that provide database access have become increasingly popular among developers building AI-powered applications. Great, except…

This expansion of MCP Servers (what I call these days “MCP Apps” and also known as “integrations”) into database connectivity introduces significant new attack surfaces that many developers haven’t fully considered. While previous MCP Server vulnerabilities have primarily focused on command injection attacks in Node.js implementations, I would like to share here a new class of security issues is emerging around improper access control in database-connected MCP Servers. This isn’t your typical SQL injection vulnerability, but it’s in close proximity.

The Simple PSQL MCP Server demonstrates this example of MCP security challenges. Unlike the command injection vulnerabilities we’ve seen in tools like the GitHub Kanban MCP Server and iOS Simulator MCP Server, this Python-based MCP Server implementation has flawed query read-only controls that would allow SQL injection, resulting in denial of service and other SQL bypasses.

The vulnerability demonstrates a critical lesson for MCP Server developers: security cannot be achieved through naive input filtering, especially when dealing with powerful systems like PostgreSQL that expose extensive functionality through seemingly innocuous SELECT queries.

DISCLAIMER AND DISCLOSURE: I have reached out via responsible security disclosure guidelines to the maintainer of simple-psql-mcp to report this security issue and they have acknowledged they are aware and that the README has a Security section that clearly communicates the dangers of SQL injection in the project’s code and that it is meant to be an educational project meant as a getting-started template creation only.

The Dangerous Assumption of “Read-Only” Database Access

Database “read-only” access is often misunderstood by developers who assume that restricting users to SELECT statements automatically prevents any harmful operations and side effects such as database queries in the form of DELETE or INSERT that modify the database. This assumption underlies the flawed security model implemented in the Simple PSQL MCP Server.

The server attempts to enforce read-only access through a basic string check that verifies queries start with “SELECT”:

@mcp.tool()

async def execute_query(

query: str = Field(description="SQL query to execute (SELECT only)"),

limit: Optional[int] = Field(default=DEFAULT_QUERY_LIMIT, description="Maximum number of rows to return"),

ctx: Context = None

) -> str:

"""Execute a read-only SQL query against the database"""

# Validate query - simple check for read-only

query = query.strip()

if not query.lower().startswith("select"):

return "Error: Only SELECT queries are allowed for security reasons."

try:

pool = ctx.request_context.lifespan_context.pool

async with pool.acquire() as conn:

result = await conn.fetch(query)

This approach fundamentally misunderstands how modern database systems work. PostgreSQL, like many advanced database systems, provides extensive functionality through functions that can be called within SELECT statements, making the “SELECT-only” restriction largely meaningless from a security perspective.

PostgreSQL Functions: The Hidden Attack Surface

PostgreSQL exposes many built-in functions that can perform administrative operations, manipulate data, and affect system behavior. Many of these functions are designed for legitimate administrative purposes but become dangerous when accessible to untrusted users.

Let’s see one example where PostgreSQL provides an administrative function that can cause serious harm when invoked through SELECT queries:

-- Terminate active database connections per process ID

SELECT pg_terminate_backend(pid);

-- Cancel running queries

SELECT pg_cancel_backend(pid) FROM pg_stat_activity WHERE query LIKE '%expensive_operation%';

-- Force database checkpoint (can cause performance issues)

SELECT pg_start_backup('malicious_backup', true);

-- Reload configuration (can disrupt service)

SELECT pg_reload_conf();

Information Disclosure Through System Views

Beyond administrative functions, PostgreSQL provides extensive system views that can leak sensitive information:

-- Expose all running queries (potential data leakage)

SELECT pid, usename, state, query FROM pg_stat_activity;

-- Show database configuration parameters

SELECT name, setting FROM pg_settings WHERE name LIKE '%password%';

-- List all database schemas and tables

SELECT schemaname, tablename FROM pg_tables;

Real-World Exploitation Scenario

The vulnerability can be exploited through a multi-step attack that demonstrates both denial of service and information disclosure capabilities:

Step 1: Initiate a Resource-Intensive Operation

Simulate a long-running operation that would be a legitimate query in a read-only context:

SELECT pg_sleep(300); -- Sleep for 5 minutes

Step 2: Information Gathering

Now, can we find that long running query?

-- Gather intelligence about database activity

SELECT pid, usename, state, query, backend_start, state_change

FROM pg_stat_activity

WHERE state = 'active';

This query reveals:

  • Active process IDs (PIDs)
  • Usernames of connected users
  • Current query states
  • Actual SQL queries being executed (information disclosure)
  • Connection timestamps

Step 3: Denial of Service Attack

From the previous step, we can grab the PID of the long-running query and terminate it:

-- Terminate the long-running process

SELECT pg_terminate_backend(12345); -- Replace with actual PID from step 2

Step 4: Escalation and Persistence

-- Attempt to disrupt multiple connections

SELECT pg_terminate_backend(pid)

FROM pg_stat_activity

WHERE usename != 'admin' AND state = 'active';

Python MCP Server Security Considerations

This vulnerability highlights unique security challenges in Python-based MCP Server implementations compared to the Node.js servers I’ve examined previously (mentioned and linked at the top of this article). Python’s strong typing and mature database libraries can provide good security foundations, but they also create different attack surfaces:

Python database drivers like asyncpg (commonly used with PostgreSQL) provide parameterized queries by default, which helps prevent SQL injection. However, they don’t provide semantic analysis of SQL queries, meaning they can’t distinguish between “safe” and “dangerous” SELECT statements.

Implementing Proper Database Access Control

Effective database security for MCP Servers requires a multi-layered approach that goes far beyond simple string filtering:

1. Database-Level Permissions

The most effective protection comes from proper database user permissions:

-- Create a restricted user for MCP Server connections

CREATE USER mcp_readonly WITH PASSWORD 'secure_password';

-- Grant only SELECT permissions on specific tables

GRANT SELECT ON public.users TO mcp_readonly;

GRANT SELECT ON public.products TO mcp_readonly;

-- Explicitly revoke dangerous permissions

REVOKE ALL ON SCHEMA pg_catalog FROM mcp_readonly;

REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA pg_catalog FROM mcp_readonly;

2. Query Allowlist

Implement a query allowlist that defines safe queries explicitly:

ALLOWED_QUERIES = {

"get_users": "SELECT id, name FROM users WHERE active = true",

"get_products": "SELECT id, name, price FROM products WHERE available = true"

}

Summary on MCP Server Security

MCP Servers exist at critical trust boundaries between AI agents and sensitive systems. Prior research has called it out as the “lethal trifecta”. Developers must carefully consider what capabilities they expose as part of the tools and how those capabilities can be abused.

The emergence of database-connected MCP Servers like the Simple PSQL implementation signals a maturity of the MCP ecosystem but also introduces more complex security challenges, and risks, especially as developers may not fully grasp security controls. As a reference for future developers, the “SELECT-only” approach represents a fundamental misunderstanding of database security that can have serious consequences in production environments, and MCP Servers developers should take heed of this lesson.


For comprehensive guidance on secure database programming and access control implementation, explore my resources at Node.js Security and follow my security research at lirantal.com.


References for prior MCP Servers security disclosures:

  1. GitHub Kanban MCP Server Command Injection Advisory
  2. iOS Simulator MCP Server Command Injection Advisory
  3. Node.js Secure Coding: Command Injection Defense
  4. PostgreSQL Security Documentation