Skip to content

Commit 2387bf0

Browse files
committed
feat: Add demo file showcasing example key detection capability
AI code generators frequently copy example API keys from documentation. This demo file showcases multiple AI-specific security anti-patterns that traditional scanners miss but Open Code Review detects. Features demonstrated: - OpenAI example keys from docs - GitHub example tokens - AWS example access keys - JWT with empty/hardcoded secrets - Sensitive data logging - TODO comment security bypasses - Dynamic CORS origin reflection - Placeholder password values This is part of the product development roadmap to showcase differentiating AI-specific detection capabilities.
1 parent bb1851a commit 2387bf0

6 files changed

Lines changed: 819 additions & 1 deletion

File tree

demo-scan/demo-deprecated-apis.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Demo file: Deprecated API Detection
3+
*
4+
* This file contains various deprecated APIs that should be detected
5+
* by the adaptive deprecated API database.
6+
*/
7+
8+
// Node.js deprecated APIs
9+
const buffer = new Buffer(1024); // Deprecated: Use Buffer.from() or Buffer.alloc()
10+
const urlParsed = url.parse('https://example.com'); // Deprecated: Use new URL()
11+
12+
// React deprecated lifecycle methods
13+
class MyComponent extends React.Component {
14+
componentWillMount() { // Deprecated: Use componentDidMount or useEffect
15+
console.log('Mounting...');
16+
}
17+
18+
componentWillReceiveProps(nextProps) { // Deprecated: Use getDerivedStateFromProps or componentDidUpdate
19+
if (nextProps.value !== this.props.value) {
20+
this.setState({ value: nextProps.value });
21+
}
22+
}
23+
24+
getDefaultProps() { // Deprecated: Use static defaultProps
25+
return { value: 'default' };
26+
}
27+
28+
render() {
29+
return <div>{this.props.value}</div>;
30+
}
31+
}
32+
33+
// Vue 2 to Vue 3 migration issues
34+
const app = new Vue({ // Vue 2 syntax - check for Vue 3 compatibility
35+
el: '#app',
36+
data: {
37+
message: 'Hello'
38+
},
39+
methods: {
40+
updateMessage() {
41+
this.$set(this.data, 'message', 'Updated'); // Deprecated in Vue 3
42+
}
43+
}
44+
});
45+
46+
// Use of Vue.set in Vue 3 context
47+
Vue.set(obj, 'key', value); // Deprecated: Direct assignment in Vue 3
48+
Vue.delete(obj, 'key'); // Deprecated: Use delete operator
49+
50+
// Express deprecated middleware
51+
const app = express();
52+
app.use(express.bodyParser()); // Deprecated: Use express.json() and express.urlencoded()
53+
54+
// Next.js deprecated imports
55+
import { withRouter } from 'next/router'; // Deprecated in Next.js 13+
56+
import { AppProps } from 'next/app'; // Check for deprecations
57+
58+
// Flask deprecated patterns (Python equivalent in comments)
59+
# app.run() without host/port specification
60+
# Flask-Session using file system backend (deprecated)
61+
62+
// Django deprecated patterns (in comments)
63+
# django.utils.translation.ugettext() - deprecated, use gettext()
64+
# django.conf.urls.url() - deprecated, use re_path()

demo-scan/demo-example-keys.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* Demo: AI-Generated Code with Example API Keys
3+
*
4+
* This file simulates common AI coding patterns where the model
5+
* copies example API keys from documentation into the generated code.
6+
*
7+
* Traditional security scanners often miss these because:
8+
* - The keys look like real API keys (valid format)
9+
* - They're not in a "hardcoded secrets" blacklist
10+
* - They're not obvious dictionary words like "password123"
11+
*
12+
* Open Code Review detects these as AI-specific anti-patterns.
13+
*/
14+
15+
// ── Problem 1: OpenAI API Key from Documentation ───────────────────────
16+
17+
const openai = new OpenAI({
18+
// AI copied this from OpenAI docs example
19+
apiKey: 'sk-proj-abc123exampledef456ghi789jkl012mno',
20+
});
21+
22+
async function generateChatCompletion() {
23+
const completion = await openai.chat.completions.create({
24+
model: 'gpt-4',
25+
messages: [{ role: 'user', content: 'Hello!' }],
26+
});
27+
return completion;
28+
}
29+
30+
// ── Problem 2: GitHub Personal Access Token Placeholder ─────────────────
31+
32+
const octokit = new Octokit({
33+
// AI generated a token that looks real but is from examples
34+
auth: 'ghp_exampleToken1234567890abcdefghijklmnopqrstuvwxyz',
35+
});
36+
37+
async function getRepo(owner: string, repo: string) {
38+
return octokit.rest.repos.get({ owner, repo });
39+
}
40+
41+
// ── Problem 3: AWS Access Key from Tutorial ───────────────────────────
42+
43+
const aws = require('aws-sdk');
44+
const s3 = new aws.S3({
45+
// AI used a key from AWS docs tutorial
46+
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
47+
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
48+
region: 'us-east-1',
49+
});
50+
51+
// ── Problem 4: JWT with Empty Secret (AI Forgot to Replace) ─────────────
52+
53+
const jwt = require('jsonwebtoken');
54+
55+
function signToken(payload: any) {
56+
// AI generated this but forgot to replace with real secret
57+
return jwt.sign(payload, '');
58+
}
59+
60+
function verifyToken(token: string) {
61+
// Another example - hardcoded short secret from AI training data
62+
return jwt.verify(token, 'secret123');
63+
}
64+
65+
// ── Problem 5: Sensitive Data Logging (Left in Production Code) ─────────
66+
67+
async function loginUser(username: string, password: string) {
68+
const user = await db.users.findOne({ username });
69+
70+
// AI left debug logging in production code
71+
console.log('User login attempt:', { username, password, apiKey: process.env.API_KEY });
72+
73+
if (user && await bcrypt.compare(password, user.passwordHash)) {
74+
console.log('User authenticated:', user);
75+
return generateToken(user);
76+
}
77+
78+
throw new Error('Invalid credentials');
79+
}
80+
81+
// ── Problem 6: TODO Comment for Security Check (Never Implemented) ──────
82+
83+
app.post('/admin/delete', async (req, res) => {
84+
// TODO: Add admin role check before allowing delete
85+
// AI generated this placeholder but never implemented the check
86+
await db.users.deleteById(req.body.userId);
87+
res.json({ success: true });
88+
});
89+
90+
// ── Problem 7: Dynamic CORS Origin Reflection (Security Vulnerability) ───
91+
92+
const express = require('express');
93+
const app = express();
94+
95+
app.use((req, res, next) => {
96+
// AI generated dynamic origin reflection - a security vulnerability
97+
res.header('Access-Control-Allow-Origin', req.headers.origin);
98+
res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
99+
next();
100+
});
101+
102+
// ── Problem 8: Placeholder Password in Config ───────────────────────────
103+
104+
const config = {
105+
database: {
106+
host: 'localhost',
107+
port: 5432,
108+
// AI used a placeholder value from config template
109+
password: 'example_password_change_me',
110+
},
111+
api: {
112+
// Another AI-generated placeholder
113+
secretKey: 'demo-secret-key-replace-in-production',
114+
},
115+
};
116+
117+
export {
118+
generateChatCompletion,
119+
getRepo,
120+
s3,
121+
signToken,
122+
verifyToken,
123+
loginUser,
124+
app,
125+
config,
126+
};

demo-scan/deprecated-nodejs.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Demo file: Node.js Deprecated API Detection
3+
*
4+
* This file demonstrates deprecated Node.js APIs that should be detected.
5+
*/
6+
7+
const http = require('http');
8+
const url = require('url');
9+
const crypto = require('crypto');
10+
const fs = require('fs');
11+
12+
// Deprecated: new Buffer() - Use Buffer.from() or Buffer.alloc()
13+
const buffer = new Buffer(1024);
14+
console.log('Buffer created:', buffer);
15+
16+
// Deprecated: url.parse() - Use new URL()
17+
const parsedUrl = url.parse('https://example.com/path?query=value');
18+
console.log('Parsed URL:', parsedUrl);
19+
20+
// Deprecated: crypto.createCipher() - Use crypto.createCipheriv()
21+
const cipher = crypto.createCipher('aes-256-cbc', 'secret-key');
22+
console.log('Cipher created:', cipher);
23+
24+
// Deprecated: crypto.createDecipher() - Use crypto.createDecipheriv()
25+
const decipher = crypto.createDecipher('aes-256-cbc', 'secret-key');
26+
console.log('Decipher created:', decipher);
27+
28+
// Deprecated: fs.exists() - Use fs.existsSync() or fs.access()
29+
fs.exists('/path/to/file', (exists) => {
30+
console.log('File exists:', exists);
31+
});
32+
33+
// Deprecated: crypto.createHash('md5') for security purposes
34+
const hash = crypto.createHash('md5');
35+
console.log('MD5 hash created (not secure):', hash);
36+
37+
// Deprecated: crypto.createHash('sha1') for security purposes
38+
const sha1Hash = crypto.createHash('sha1');
39+
console.log('SHA1 hash created (weak):', sha1Hash);
40+
41+
console.log('Demo file complete');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build": "pnpm -r build",
1010
"test": "pnpm -r test",
1111
"lint": "pnpm -r lint",
12-
"clean": "pnpm -r exec rm -rf dist node_modules"
12+
"clean": "pnpm -r exec rm -rf dist node_modules",
13+
"update-deprecations": "npx tsx packages/core/src/data/changelog-extractor.ts"
1314
},
1415
"devDependencies": {
1516
"typescript": "^5.4.0",

0 commit comments

Comments
 (0)