SDE · Coding Rules Admin

Classic ASP / VBScript Coding Rules

Every time we hit a new error in ASP work, add the rule here so Claude never hits it again. Currently tracking 55 rules.

Add a new rule

Paste directly from an error message or Claude's fix explanation. Only Category and Title are required — fill in what you have.

Existing Rules

Click Edit on any row to load it into the form above. Deleting soft-archives the rule (IsActive=0) — not gone forever, but hidden from GetCodingRules.asp.

Cookies & Auth

#TitleSevTagsActive
8.1Request.Cookies — coerce with & "" and always validatecriticalcookie,auth,securityon
8.2Admin pages start with an explicit Session("account_id") check that 302s on failcriticalauth, session, admin, security, redirecton

Database

#TitleSevTagsActive
3.1MARS deadlock — one open recordset per connectioncriticaldatabase,mars,recordset,sqlserveron
3.2Always close recordsets and null the referencewarningdatabase,recordset,cleanupon
3.3Always SQL-escape user values before building SQLcriticaldatabase,security,sql-injectionon
3.4Clamp form input lengths to column width before SQLwarningdatabase,validation,inputon
3.5Migrations must be idempotentwarningdatabase,migration,idempotenton
3.6Admin check on BN_Members is MemberRole='admin', NOT a boolean IsAdmin columncriticaldatabase,schema,admin,members,bn_memberson
3.7Never SELECT NVARCHAR(MAX) columns alongside short fields you actually need to readcriticaldatabase, ado, nvarchar, max, cursor, sqloledbon
3.8Single-field edits need a surgical UPDATE action — never reuse the bulk update pathwarningdatabase, update, partial, ux, apion
3.9Auto-create-on-first-hit table patterns fail silently — always verify with a SELECTwarningdatabase, ddl, permissions, migration, loggingon
3.10Wrap every conn.Execute in On Error Resume Next + JSON error replycriticalsql, error-handling, ajax, json, 500, oledbon
3.11Grep the codebase for table/column names before writing a new querycriticalsql, schema, joins, oledb, 80040e14on
3.12Every transactional SendGrid email must write a row to EmailsLogbest-practiceemail, sendgrid, logging, audit, emailslogon
3.13Per-show activity goes in teamadmin_history; one row per show on the invoicebest-practicehistory, audit, activity, shows, invoice, logon

Error Handling

#TitleSevTagsActive
9.1Master defensive pattern — never let data crash the pagecriticalerror-handling,defensiveon
9.2CDO.Message — set HTMLBody before touching HTMLBodyPart.Charsetcriticalcdo, email, smtp, charset, orderon
9.3Call Response.Clear before writing JSON error outputwarningresponse, buffer, json, error, apion
9.4Keep On Error Resume Next scope tight — never re-enable strict errors mid-Subwarningerror, oern, on-error, scope, vbscripton

File Organization

#TitleSevTagsActive
4.1Define helper Functions at the TOP of the ASP filewarningfile-organization,hoistingon
4.2Never use <!--#include--> inside a conditionalwarningfile-organization,includeon
4.3Use #include virtual="/path" for shared config — never duplicate Const declarationscriticalinclude, const, virtual, file, organizationon
4.4Always verify FTP/Dreamweaver upload actually replaced the server filewarningdeployment, ftp, dreamweaver, file, syncon
4.5Every ASP file starts with the UTF-8 + CodePage blockwarningasp, encoding, utf-8, charset, codepageon
4.6Gate new-table reads behind an On Error check that points at the migration filebest-practiceasp, migration, error-handling, schema, deployon

HTML Rendering

#TitleSevTagsActive
7.1Always HTMLEncode user-provided valuescriticalhtml,xss,escapeon
7.2Use a separate attribute-safe escape for HTML attributeswarninghtml,escape,attributeon
7.3JS-safe inline needs a JSReady helperwarninghtml,javascript,escapeon
7.4Inline form values must be HTMLEncoded — including value="" attributeswarninghtml, encoding, attribute, xss, formson
7.5Don't scope base text/background rules to #editor onlycriticalcss, cms, page-builder, editor, scope, embedon
7.6Default state of every element must be visible (no JS-dependent reveals)criticalcss, animation, opacity, reveal, javascript, cmson
7.7Override the CMS .widget-container background, not just the inner form fieldswarningcss, cms, widget, form, override, importanton
7.8Never paste the page-wrapper + fonts <link> block more than oncewarninghtml, cms, nesting, duplication, wrapperon
7.9Don't rely solely on a Font Awesome kit URL — add a public CDN fallbackwarningfontawesome, icons, cdn, kit, domain-lockon

LLM APIs

#TitleSevTagsActive
6.1Use ===SECTION=== delimiters, not nested JSON-in-stringcriticalai,llm,parsing,geminion
6.2Set maxOutputTokens generously (8192+)warningai,llm,tokens,geminion
6.3In the system prompt, say "no JSON, no markdown, no preamble"warningai,llm,promptingon
6.4For JSON output from Gemini, set responseMimeType:"application/json" — do not just hopewarningllm, gemini, json, responsemimetype, parseon

Null Handling

#TitleSevTagsActive
2.1Null & "" = Null (not "")criticalnull,vbscript,stringon
2.2Always coerce recordset field reads with & ""criticalnull,recordset,databaseon
2.3Mid/Left/InStr on non-string Variants throws Type mismatchcriticalnull,vbscript,string,dictionaryon
2.4CDate can throw Type mismatch even when IsDate is Truecriticaldate,cdate,vbscripton
2.5Read migration-added columns defensivelywarningmigration,schema,defensiveon
2.6Always wrap recordset values with HE() or HA() before outputcriticalvbscript, null, htmlencode, xss, helperson

User Input

#TitleSevTagsActive
5.1Coerce every form value with & "" before usingwarninginput,form,coerceon
5.2Validate numeric input with IsNumeric before castingcriticalinput,validation,numericon
5.3Multi-valued checkboxes join with ", " automaticallybest-practiceinput,form,checkboxon
5.4Escape every Request value before concatenating into SQLcriticalsql-injection, security, escape, apostrophe, request-formon

VBScript Syntax

#TitleSevTagsActive
1.1Identifiers cannot start with an underscorecriticalvbscript,syntax,namingon
1.2Single-line If/Then cannot be chained with ElseIfcriticalvbscript,syntax,control-flowon
1.3Functions return by assigning to the function namecriticalvbscript,syntax,functionon
1.4VBScript has no native IIf — define your owncriticalvbscript,syntax,iifon
1.5Never Dim the same variable twice in one Sub/Functioncriticalvbscript, syntax, dim, scope, compileon
1.6Use CDbl/CCur for large numbers — CLng overflows at ~2.1 billioncriticalvbscript, syntax, clng, overflow, casting, numericon
1.7Don't colon-pack If/Else across a function bodycriticalvbscript, syntax, function, colons, parseron