Zum Hauptinhalt springen
LIVE
CVSS 6.9CVE-2026-137684 | A security flaw has been discovered in eosphoros-ai DB-GPT up to 0.8.3. This affects the function editor_sql_run of the file packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/editor/api_editor_v1.py of the component Editor SQL Run API. Performing a manipulation of the argument db_name results in authorization bypass. It is possible to initiate the attack remotely. The exploit has been released to the public and may be used for attacks. The pull request to fixCVSS 8.7CVE-2026-137992 | libexpat through 2.11.0 contains a denial of service vulnerability in defineAttribute() of lib/xmlparse.c that fails to detect duplicate non-ID #IMPLIED or #REQUIRED attribute declarations. Attackers can supply a crafted XML document with repeated ATTLIST declarations in an internal DTD subset to cause quadratic CPU consumption in storeAtts() during parsing.CVSS 8.5CVE-2026-137994 | Leo through 6.8.10 contains an insecure deserialization vulnerability that allows attackers to execute code by embedding pickled data in unknown XML attributes of .leo outlines. Attackers can place a pickle __reduce__ gadget in a or element attribute that resolveUa passes to pickle.loads, executing code with user privileges when the outline is opened.CVSS 7.0CVE-2026-137995 | FOG Project before 1.6.0.119 contains an information disclosure vulnerability that allows unauthenticated attackers to obtain host tokens from status/hostgetkey.php by supplying a host MAC address. Attackers can present the token to service/hostinfo.php to retrieve decrypted Active Directory join credentials and Windows product keys during deployment windows.CVSS 6.8CVE-2026-137996 | Zettlr before 4.11.0 fails to validate URI schemes in Markdown link targets, allowing attackers to launch arbitrary registered protocol handlers via Electron shell.openExternal without confirmation. Attackers can craft documents whose Ctrl/Cmd-clicked links use smb:// to leak NTLM credential hashes on Windows or invoke custom protocol handlers with attacker-controlled parameters.CVSS 8.5CVE-2026-137997 | HCIPy through 0.7.1 contains an insecure deserialization vulnerability that allows attackers to execute code by supplying crafted .pkl files to read_field, read_grid or read_mode_basis. Because hcipy/util/io.py selects pickle by file extension and calls pickle.load, a __reduce__ gadget in a pupil, apodizer, PSF or mode-basis file runs code with the user's privileges.CVSS 8.5CVE-2026-137998 | Detoxify 0.5.3 through 0.5.4 contains an insecure deserialization vulnerability in load_checkpoint that allows attackers to execute code by supplying a crafted checkpoint file. Attackers can embed a pickle __reduce__ gadget in a .ckpt file loaded via torch.load with weights_only=False to run code with the user's privileges.CVSS 8.5CVE-2026-137999 | JSONSchema2PoPo2 through 3.0.3 contains a code injection vulnerability that allows attackers to inject Python code by supplying JSON Schema default or format values that are written unescaped. Attackers can place a single quote in a string property default to break out of the literal in the generated __init__ signature, executing injected code when the generated module is imported.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

How To Set Up React Context

Prop drilling is usually the reason we reach for React Context: state that started in one component ends up threaded through five layers of props, and every…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 6 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung

Prop drilling is usually the reason we reach for React Context: state that started in one component ends up threaded through five layers of props, and every layer in between has to know about data it doesn't use. Context fixes that. But "use Context" isn't a setup — there are a dozen ways to structure the files, and most of them share a papercut that has annoyed me in every codebase I've worked in.



This article walks through the setup I've landed on. It's three files, it makes "Go to Definition" actually useful, and it uses a lint rule to make the one risky part of the pattern impossible to get wrong. The running example is a tic-tac-toe game — the full working project is at react-context-boilerplate-example.






The papercut



Here's the workflow friction. In a typical Context setup, components access state through a hook:




const { winner, resetGame } = useGame();






You're reading a component, you want to know how resetGame actually works, so you Command + Click on useGame. And you land... in a file that contains a useContext call and nothing else. The actual state management — the useState calls, the update logic — lives inside the provider component in a different file. So you go searching for it.



Every. Single. Time.



The setup below fixes that: Go to Definition on the consumer hook lands in the same file as all the state-management logic.






The structure



Three pieces, two files:




src/context/
├── GameContext.ts ← the context, the public hook, AND the state logic
└── GameProvider.tsx ← a thin shell






The trick is that the state management isn't written inside the provider component. It's written as a hook, in the same file as the consumer hook.






Step 1: The context file



GameContext.ts contains three things: the context object, the public hook that components use, and a private hook holding all the state logic.




import { createContext, useContext, useState } from 'react';
import type { GameContextI, Winner, BoardContent, Player } from '../types';
import {
INITIAL_BOARD_CONTENT,
INITIAL_CURR_PLAYER,
INITIAL_WINNER,
} from '../constants/gameConstants';

export const GameContext = createContext<GameContextI | null>(null);

// PUBLIC: components call this to access the game state.
export function useGame() {
const context = useContext(GameContext);
if (!context) {
throw new Error('useGame must be used within a GameProvider');
}
return context;
}

// PRIVATE: only GameProvider should ever call this.
export function useGameStateManagement() {
const [currPlayer, setCurrPlayer] = useState<Player>(INITIAL_CURR_PLAYER);
const [winner, setWinner] = useState<Winner>(INITIAL_WINNER);
const [boardContent, setBoardContent] = useState<BoardContent>(
INITIAL_BOARD_CONTENT,
);

const updateSquareContent = (
rowIndex: number,
colIndex: number,
value: Player,
) => {
// ...update the board, check for a winner, advance the turn...
};

const resetGame = () => {
setCurrPlayer(INITIAL_CURR_PLAYER);
setWinner(INITIAL_WINNER);
setBoardContent(INITIAL_BOARD_CONTENT);
};

return {
winner,
currPlayer,
setCurrPlayer,
boardContent,
setBoardContent,
updateSquareContent,
resetGame,
};
}






A few things to notice:





  • The context is typed as GameContextI | null and the public hook throws if the context is missing. That null check happens once, here — components never have to handle a possibly-null context, and a component rendered outside the provider fails loudly with a message that says exactly what's wrong.


  • useGameStateManagement is a real hook, so it can use useState (or useReducer, or anything else) exactly as if the logic were written inline in the provider.


  • Both hooks are in one file. Go to Definition on useGame from any component takes you here — where the state logic lives. Papercut solved.






Step 2: The thin provider



Because the logic lives in the hook, the provider has almost nothing to do:




import React from 'react';
import { GameContext, useGameStateManagement } from './GameContext';

interface GameProviderProps {
children?: React.ReactNode;
}

export default function GameProvider({ children }: GameProviderProps) {
const contextValue = useGameStateManagement();
return (
<GameContext.Provider value={contextValue}>{children}</GameContext.Provider>
);
}









Step 3: Wrap the tree and consume



Wrap the part of the tree that needs the state (here, the whole app):




createRoot(document.getElementById('root')!).render(
<StrictMode>
<GameProvider>
<App />
</GameProvider>
</StrictMode>,
);






And any component underneath just calls the public hook:




import { useGame } from './context/GameContext';

function App() {
const { winner, resetGame } = useGame();
// ...
}






No prop drilling, no null checks, and jumping to useGame's definition drops you next to the actual logic.






The catch



There's one problem with this pattern, and it's the price of the co-location: useGameStateManagement has to be exported so the provider can import it. Which means it looks importable to everyone.



If a teammate skims the file, sees an exported hook that returns the entire game state, and calls it from a component — the code will compile, render, and even sort of work. But that component gets its own, brand-new copy of the state, completely detached from the context value every other component shares. Clicking a square updates one board; the rest of the app is looking at a different one. It's the kind of bug that costs an afternoon.



A // do not call this outside GameProvider comment is a speed bump, not a wall. What I wanted was a lint error.






Enforcing it with a lint rule



I packaged this up as eslint-plugin-restrict-callers: an ESLint rule that restricts which named functions may call a given function.




npm install --save-dev eslint-plugin-restrict-callers






Then in eslint.config.js (flat config, ESLint 9+):




import restrictCallers from 'eslint-plugin-restrict-callers';

export default [
{
plugins: { 'restrict-callers': restrictCallers },
rules: {
'restrict-callers/restrict-callers': ['error', {
restrictedFunctions: [
{
functionName: 'useGameStateManagement',
allowedCallers: ['GameProvider'],
alternative: 'useGame',
},
],
}],
},
},
];






Now calling the private hook anywhere other than GameProvider fails lint with a message that tells the reader what to do instead:




error  useGameStateManagement may only be called inside GameProvider. Use useGame instead






Each entry takes a functionName (the function to protect), allowedCallers (the functions permitted to call it), and optionally an alternative to suggest — or a fully custom message. It isn't hook-specific, either: you can use it any time a function has to be exported but is only meant for one caller. And because it's just config, every new context you add is one more entry in the array.






Recap




  1. Put the context, the public consumer hook, and the private state-management hook in one file — Go to Definition on the consumer hook lands on the logic.

  2. Keep the provider a thin shell that calls the private hook and passes the result to Context.Provider.

  3. Throw from the public hook when the context is null, so misplaced components fail loudly.

  4. Enforce the public/private boundary with eslint-plugin-restrict-callers instead of a comment.



The full working example — game and all — is at react-context-boilerplate-example, and the plugin lives at eslint-plugin-restrict-callers. If you've felt this papercut too, I'd love to hear how you've handled it.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Topluluk tartışması ve yorumlar

🌐 Ana sohbete katıl

Tartışmayı başlat: Social Chat yayın akışı veya yukarıdaki ekleme formuyla uzman katkısı gönder.

Community Rating &amp; Social Proof
⭐ Okuyucu Puanı
–
Ø / 5.0
Hiçbir okuyucu henüz yorum yok
Bu makale yararlı mıydı?
0
Değerlendirmenizi gönderin
Detaylı değerlendirme (isteğe bağlı)
İçerik ve Kalite
Kaynak ve Güvenilirlik
Güncellik
Security Briefing Ücretsiz · Tek tıkla abonelikten çıkma

Zeka Digest - ücretsiz

Günlük en önemli güvenlik haberi · herhangi bir zamanda alınabilir

İlgili Story Cluster & Kaynaklar (vector AI)

2 Cluster
2 Kaynaklar
OpenAI counter-sues Apple over trade secret theft
AppleInsider News 2 saat önce
1 başka bir kaynak
Benzer katkılar
🔍 Verwandte News

Auch interessante Nachrichten How To Set Up React Context

Thematisch verwandte Begriffe: React, Context · 6 Treffer

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Yorumlar yüklenir..
Update to Update
Widgets & Topics
Loading widgets…
Nächster Beitrag