CWE-270 Base Draft

Privilege Context Switching Error

This vulnerability occurs when an application fails to properly manage user permissions while moving between different security contexts, potentially allowing unauthorized actions.

Definition

What is CWE-270?

This vulnerability occurs when an application fails to properly manage user permissions while moving between different security contexts, potentially allowing unauthorized actions.
Think of this as a security guard who forgets to check their keys when moving between restricted areas. In software, this happens when a process or thread switches between different privilege levels—like going from a low-privilege user mode to a high-privilege kernel mode, or when handling data from different trust zones—but doesn't correctly reset or validate its access rights. The system might carry over elevated permissions from a previous task, creating a window where an attacker can execute code or access data they shouldn't have. For developers, the core issue is a broken trust boundary during state transitions. Common pitfalls include temporarily raising privileges for a specific task but failing to drop them immediately afterward, or incorrectly assuming a new context inherits a safe default. To prevent this, always adopt the principle of least privilege explicitly during context switches: deliberately set the required permissions for the new operation and never rely on implicit state. Audit any code that changes execution context, such as system calls, callback handlers, or data parsers, to ensure privilege cleanup is mandatory and fail-safe.
Real-world impact

Real-world CVEs caused by CWE-270

  • Web browser cross domain problem when user hits "back" button.

  • Web browser cross domain problem when user hits "back" button.

  • Cross-domain issue - third party product passes code to web browser, which executes it in unsafe zone.

  • Run callback in different security context after it has been changed from untrusted to trusted. * note that "context switch before actions are completed" is one type of problem that happens frequently, espec. in browsers.

How attackers exploit it

Step-by-step attacker path

  1. 1

    Identify a code path that handles untrusted input without validation.

  2. 2

    Craft a payload that exercises the unsafe behavior — injection, traversal, overflow, or logic abuse.

  3. 3

    Deliver the payload through a normal request and observe the application's reaction.

  4. 4

    Iterate until the response leaks data, executes attacker code, or escalates privileges.

Vulnerable code example

Vulnerable pseudo

MITRE has not published a code example for this CWE. The pattern below is illustrative — see Resources for canonical references.

Vulnerable pseudo
// Example pattern — see MITRE for the canonical references.
function handleRequest(input) {
  // Untrusted input flows directly into the sensitive sink.
  return executeUnsafe(input);
}
Secure code example

Secure pseudo

Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Prevention checklist

How to prevent CWE-270

  • Architecture and Design / Operation Very carefully manage the setting, management, and handling of privileges. Explicitly manage trust zones in the software.
  • Architecture and Design / Operation Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
  • Architecture and Design Consider following the principle of separation of privilege. Require multiple conditions to be met before permitting access to a system resource.
Detection signals

How to detect CWE-270

SAST High

Run static analysis (SAST) on the codebase looking for the unsafe pattern in the data flow.

DAST Moderate

Run dynamic application security testing against the live endpoint.

Runtime Moderate

Watch runtime logs for unusual exception traces, malformed input, or authorization bypass attempts.

Code review Moderate

Code review: flag any new code that handles input from this surface without using the validated framework helpers.

Plexicus auto-fix

Plexicus auto-detects CWE-270 and opens a fix PR in under 60 seconds.

Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.

Frequently asked questions

Frequently asked questions

What is CWE-270?

This vulnerability occurs when an application fails to properly manage user permissions while moving between different security contexts, potentially allowing unauthorized actions.

How serious is CWE-270?

MITRE has not published a likelihood-of-exploit rating for this weakness. Treat it as medium-impact until your threat model proves otherwise.

What languages or platforms are affected by CWE-270?

MITRE has not specified affected platforms for this CWE — it can apply across most application stacks.

How can I prevent CWE-270?

Very carefully manage the setting, management, and handling of privileges. Explicitly manage trust zones in the software. Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need…

How does Plexicus detect and fix CWE-270?

Plexicus's SAST engine matches the data-flow signature for CWE-270 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.

Where can I learn more about CWE-270?

MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/270.html. You can also reference OWASP and NIST documentation for adjacent guidance.

Related weaknesses

Weaknesses related to CWE-270

CWE-269 Parent

Improper Privilege Management

This vulnerability occurs when an application fails to correctly manage user permissions, allowing someone to perform actions or access…

CWE-250 Sibling

Execution with Unnecessary Privileges

This vulnerability occurs when software runs with higher permissions than it actually needs to perform its tasks. This excessive privilege…

CWE-266 Sibling

Incorrect Privilege Assignment

This vulnerability occurs when a system mistakenly grants a user, process, or entity a specific permission or privilege they should not…

CWE-267 Sibling

Privilege Defined With Unsafe Actions

This vulnerability occurs when a system grants a user, role, or process a specific permission that can be misused to perform dangerous,…

CWE-268 Sibling

Privilege Chaining

Privilege chaining occurs when an attacker combines two separate permissions or capabilities, neither of which is dangerous on its own, to…

CWE-271 Sibling

Privilege Dropping / Lowering Errors

This vulnerability occurs when a system or process fails to reduce its elevated permissions before transferring control of a resource to a…

CWE-274 Sibling

Improper Handling of Insufficient Privileges

This vulnerability occurs when an application fails to properly manage situations where it lacks the necessary permissions to execute an…

CWE-648 Sibling

Incorrect Use of Privileged APIs

This vulnerability occurs when software incorrectly uses functions that require special permissions. Attackers can exploit these mistakes…

Ready when you are

Don't Let Security
Weigh You Down.

Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.